【发布时间】:2014-09-17 07:04:33
【问题描述】:
我有 angularJs 控制器
angular.module('App.ctrl.guests', [])
.controller('guestsController', ['$scope', '$http', '$location', '$timeout', 'guestsService', function ($scope, $http, $location, $timeout, guestsService) {
$scope.tiles = [];
}])
茉莉花测试
/// <reference path="~/Scripts/angular.js" />
/// <reference path="../../ProjectWeb/Scripts/app/guests/guestsCtrl.js" />
/// <reference path="~/Scripts/angular-mocks.js" />
/// <reference path="~/Scripts/jasmine.js" />
'use strict';
describe('App.ctrl.guests', function () {
var scope, controller;
beforeEach(function () {
module('App.ctrl.guests')
});
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('guestsController', {
$scope: scope
});
}));
it('should have empty array', function () {
expect(scope.tiles).toBe([]);
});
})
每次我在 Visual Studio chutzpah 中运行时都会得到:
ReferenceError:找不到变量:模块在 文件:///.../JasmineTests/guestsControllerTest.js (第 5 行)
ReferenceError:找不到变量:注入 file:///.../JasmineTests/guestsControllerTest.js(第 12 行)
参考 angular.js 是否有问题,而 jasmine 不知道什么是模块/注入关键字?这是我第一次做js测试:/
【问题讨论】:
-
您是否包含了对这些库的引用?我自己没有使用 Visual Studio,但我认为这个人正在做和你一样的设置rosher.co.uk/post/2013/10/22/…
-
是的,我添加引用,我更新代码。
-
谢谢gillesc,我在这篇文章中将js文件拖放到测试文件中,现在路径是正确的;)
标签: javascript angularjs visual-studio-2012 jasmine chutzpah