我的角度腳本是這樣的:
var app = angular.module("myApp", []);
app.controller('TestController', function ($scope) {
$scope.test= "TEST";
});
我的測試文件看起來像這樣:
describe('first test', function() {
var $scope;
beforeEach(function(){
module('myApp');
inject(function($rootScope, $controller) {
$scope = $rootScope.$new();
ctrl = $controller('TestController', {
$scope: $scope
});
});
it('scope should have test', function() {
expect($scope.test).toEqual("TEST");
});
});
該測試失敗,說$ scope.test未定義。我在Chrome中進行調試,發現$ scope有一堆屬性,但沒有一個是測試。我在網上瀏覽了幾個例子,它們看起來都很相似。我不太確定我在這裏做錯了什麼,我卡住了......我試圖添加$控制器注入,但我仍然有同樣的問題。
如果你認爲你會得到'$ controller'? – PSL 2014-09-21 03:30:20