gpt4 book ai didi

angularjs - Angular 模拟 `module` 导致 '[Object object] is not a function'

转载 作者:行者123 更新时间:2023-12-02 19:04:49 26 4
gpt4 key购买 nike

我正在尝试使用通过 Teaspoon 运行的 Jasmine 在 Angular 中创建一些单元测试。测试正在运行,但是我有一个简单的测试只是为了测试失败的 Controller 是否存在。我有以下测试设置。

//= 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 });
}));

})

})

require 语句由 Browserify 处理,它正在处理我的依赖项,但我也可以连接到我用于规范帮助程序的 sprocket。

在需要的应用程序内,我有

require("angular");
var controllers = require("./controllers");

var app = angular.module("app", [
"app.controllers"
]);

exports.app = app;

当我运行此测试时,出现以下错误

Failure/Error: TypeError: '[object Object]' is not a function (evaluating 'module("aialerts")')

我花了很长时间试图解决这个问题,但我不知道发生了什么。任何帮助表示赞赏。

最佳答案

我也遇到了同样的问题。更改此行:

beforeEach(module("app"))

至:

beforeEach(angular.mock.module("app"))

关于angularjs - Angular 模拟 `module` 导致 '[Object object] is not a function',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20968320/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com