我收到以下错误:TypeError: undefined is not a function
问题是常见的是模块和工厂,问题出在我的行上
var ctrl = $controllerConstructor("resetPasswordSentScreen", { $scope: scope, common: common});
这是完整的测试:
describe('resetPasswordSentScreen', function () {
var scope, $controllerConstructor;
beforeEach(module('common', 'app'));
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
$controllerConstructor = $controller;
}));
it('it should navigate to the correct url when backToLogin is called ', function (common) {
var ctrl = $controllerConstructor("resetPasswordSentScreen", { $scope: scope, common: common });
var mocklocation = sinon.stub({ url: function () {}});
expect(scope.backToLogin()).toBe(mocklocation.url);
});
});
答案 0 :(得分:3)
这不是问题,问题是你不能像在代码中那样将东西注入到函数中。要注入,您需要像inject
中那样拨打beforeEach
。所以,如果你想注入那个工厂,你需要这个:
it("message", inject(function(common) {
...
}));
你有注射方式。这应该有用。