javascript - AngularJS Test a Factory with Mocha -
i new mocha , angularjs unit testing want test application using mocha. have basic language tests working, cannot run tests against applications factory or controller.
i have following basic files.
apps.js
aangular.module('myapp', []);
file1.js
angular.module('myapp').factory('factory1' ...);
file2.js
angular.module('myapp').factory('factory2' ...); angular.module('myapp').factory('controller' ...); describe('main test', function() { var factorytotest; beforeeach(module('myapp')); beforeeach(inject(function (_factory_) { factorytotest = _factory_; })); describe('factory2', function () { it('should return "unknown"', function () { game = {}; expect(new factory2(game)).to.equal('unknown'); }); }); });
when run test, generates error, , not sure fix work.
error:
message: object not function stack: typeerror: object not function @ suite.<anonymous> (b:\app\test.js:5:16)
you're getting error because beforeeach function should take callback function instead of object. according angular guide on module unit testing (scroll bottom of page) :
each module can loaded once per injector. angular app has 1 injector , modules loaded once. each test has own injector , modules loaded multiple times.
Comments
Post a Comment