测试目的:
-
测试 Module 是否正常
-
测试依赖是否正常引用
模块是最顶层的容器,用来创建 directive, controller, template, service 和 resource。因此,当测试模块的时候,因此,当测试模块的时候,你其实只要看看模块是不是存在。当然这个可以在单元测试或者 Midway 测试中检查,但是建议是写在 Midway 测试中,因为代码已经可以执行了,你需要的仅仅是看看模块能不能被 AngularJS 访问。
Midway 测试:
//// test/midway/appSpec.js//describe("Midway: Testing Modules", function() { describe("App Module:", function() { var module; before(function() { module = angular.module("App"); }); it("should be registered", function() { expect(module).not.to.equal(null); }); describe("Dependencies:", function() { var deps; var hasModule = function(m) { return deps.indexOf(m) >= 0; }; before(function() { deps = module.value('appName').requires; }); //you can also test the module's dependencies it("should have App.Controllers as a dependency", function() { expect(hasModule('App.Controllers')).to.equal(true); }); it("should have App.Directives as a dependency", function() { expect(hasModule('App.Directives')).to.equal(true); }); it("should have App.Filters as a dependency", function() { expect(hasModule('App.Filters')).to.equal(true); }); it("should have App.Routes as a dependency", function() { expect(hasModule('App.Routes')).to.equal(true); }); it("should have App.Services as a dependency", function() { expect(hasModule('App.Services')).to.equal(true); }); }); });});