3

This is from the karma.conf.js file:

module.exports = function (config) {
  config.set({
      frameworks: ['mocha', 'chai'],
      files: [
        'bower_components/angular/angular.js',
        'bower_components/angular-mocks/angular-mocks.js',
        'public/ng-app/module.js',
        'public/ng-app/**/*.js',
        'test/ng/**/*.spec.js'
      ],
  ...

I am trying to use the beforeEach function with inject like this:

describe('my.test', function () {
  beforeEach(module('app'));

  var MyService;
  beforeEach(inject(function (_MyService_) {
    MyService = _MyService_;
  }));

  describe('#send', function () {
    it('exists', function () {
      expect(MyService.save).to.exist;
    });
  });

});

but the beforeEach(inject(function (...)...); part of the code causes this error when I try to run the tests:

PhantomJS 1.9.8 (Windows 8 0.0.0) my.test "before each" hook: workFn for "exists" FAILED
        Error: [$injector:modulerr] Failed to instantiate module ng due to:
        TypeError: 'undefined' is not an object (evaluating 'Function.prototype.bind.apply')

I can't figure out what the problem is. Does someone has any idea? Thanks.

commonUser
  • 599
  • 1
  • 6
  • 17

2 Answers2

5

https://github.com/angular/angular.js/issues/13794

Use a Polyfill for bind or Phantom2 or test in Chrome

Xavier Haniquaut
  • 1,003
  • 9
  • 22
1

I downgraded from Angular 1.5.0 to 1.2.29 and now tests are errors free.

commonUser
  • 599
  • 1
  • 6
  • 17