我开始学习AngularJS时并没有太多了解。 当我执行以下内容时:
.\node_modules\.bin\karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=PhantomJS
我收到了以下信息:
我得到以下消息:
WARN [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
我使用了angular-seed项目作为起点,并根据我的需求进行了调整。我想使用jasmine作为我的测试框架。因此,我基于当前的angular-seed项目编写了我的测试用例:
describe('sputnikApp.view1 module', function () {
beforeEach(module('sputnikApp.view1'));
describe('view1 controller', function () {
var scope;
beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
$controller('View1Ctrl', {$scope: scope});
}));
it("it should have has default selected priority Normal", function() {
expect(input("select.value1").val()).toBe('2');
})
});
});
我认为expect(input(...部分是jasmine框架的一部分。我添加了jasmine,但显然出现了错误,因为某些内容没有加载。我通过添加RequireJS来解决这个问题。现在我认为我快完成了,但测试用例没有运行。
我给你仓库和travis,希望能有所帮助。
我怀疑这与RequireJS有关。
我看了其他相关的问题,但没有起作用。我认为我可能在RequireJS方面过于复杂了。如果不需要它,那就更好了...
test-main.js
,请查看有关使用Karma配置RequireJS的文档页面,然后重新初始化你的karma.conf.js
。 - Michael Radionovkarma.conf.js
的框架列表中删除它即可。只有在使用 RequireJS 构建应用程序时,才应在测试中使用 RequireJS,否则根本没有必要使用它。 - Michael RadionovReferenceError: Can't find variable: input at C:/Users/Maxime/IdeaProjects/sputnik-angularjs/app/view1/view1_test.js:17
这是在移除 requireJS 后出现的错误。现在我遇到了这个错误。据我所知,input 应该在 jasmine 框架中。这里是我使用的 input 示例:链接 - Maxime Roussin-Bélangerinput
与Jasmine无关。它实际上来自于angular-scenario工具,该工具曾用于进行Angular的端到端测试,但现在已被弃用,应改用Protractor。 - Michael Radionov