造成角模拟`module`'[Object对象]不是一个函数“ [英] angular mock `module` resulting in '[Object object] is not a function'
问题描述
我试图创建一个使用茉莉花正在通过茶匙运行角一些单元测试。测试运行的,但是我有一个简单的测试只是为了测试失败控制器的存在。我有以下的测试设置。
I'm trying to create some unit tests in Angular using Jasmine being run through Teaspoon. The tests are running, however I have a simple test just to test the existence of a controller that is failing. I have the following test setup.
//= require spec_helper
require("angular");
require("angular-mocks");
var app = require("./app");
describe("My App", function() {
describe("App Controllers", function() {
beforeEach(module("app"))
it("Should have created an application controller", inject(function($rootScope, $controller){
var scope = $rootScope.$new();
ctrl = $controller("ApplicationCtrl", { $scope: scope });
}));
})
})
该声明需要通过Browserify正在处理我的依赖关系处理,但我也可以连接到我使用规范帮手其中链轮。
The require statements are processed by Browserify which is handling my dependencies, but I can also hook into sprockets which I'm using for the spec helper.
里面正在被需要的应用程序,我有
Inside the app that is being required, I have
require("angular");
var controllers = require("./controllers");
var app = angular.module("app", [
"app.controllers"
]);
exports.app = app;
当我运行这个测试,我得到以下错误产生的
When I run this test, I get the following error produced
Failure/Error: TypeError: '[object Object]' is not a function (evaluating 'module("aialerts")')
我花了相当长一段时间试图弄清楚这一点,但我不知道发生了什么事情。任何帮助AP preciated。
I've spent quite a while trying to figure this out but I have no idea what's going on. Any help appreciated.
推荐答案
我有同样的问题。改变这一行:
I had the same problem. Change this line:
beforeEach(module("app"))
到
beforeEach(angular.mock.module("app"))
这篇关于造成角模拟`module`'[Object对象]不是一个函数“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!