나는 다음과 같은 코드가 있습니다JsTestDriver로 AngularJS 컨트롤러를 테스트하는 방법은 무엇입니까?
function TestStats($xhr) {
$xhr(
'GET',
'/test-dashboard/get-projects.json',
angular.bind(this, function(code, response) {
this.projects = response.projects;
this.projects.splice(0, 0, undefined);
}));
this.$watch('project', angular.bind(this, function() {
this.testClassStats = undefined;
if (this.project) {
$xhr(
'GET',
'/test-dashboard/get-test-stats.json?project=' + this.project,
angular.bind(this, function(code, response) {
this.testClassStats = response.testClassStats;
}));
}
}));
};
TestStats.prototype.greet = function(name) {
return "Hello " + name + "!";
};
TestStats.$inject = ['$xhr'];
다음과 같은 시험 :
TestDashboardUnitTest = TestCase("TestDashboardUnitTest");
TestDashboardUnitTest.prototype.testAoeu = function() {
var xhrStub = function(method, url, callback) {
};
var testStats = new TestStats(xhrStub);
assertEquals("Hello World!", testStats.greet("Aoeu"));
};
다음과 같은 설정을 :
server: http://localhost:9876
load:
- http://code.jquery.com/jquery-1.6.2.min.js
- http://code.angularjs.org/angular-0.9.17.min.js
- web/*.js
- test/*.js
나는 시험, JsTestDriver 출력을 실행하면 :
를Total 1 tests (Passed: 0; Fails: 0; Errors: 1) (0.00 ms)
Chrome 13.0.782.112 Linux: Run 1 tests (Passed: 0; Fails: 0; Errors 1) (0.00 ms)
TestDashboardUnitTest.testAoeu error (0.00 ms): TypeError: Object #<TestStats> has no method '$watch'
TypeError: Object #<TestStats> has no method '$watch'
at new TestStats (http://127.0.0.1:9876/test/web/test-dashboard.js:13:10)
at [object Object].testAoeu (http://127.0.0.1:9876/test/test/test-dashboard-unit-test.js:9:21)
Tests failed: Tests failed. See log for details.
이 문제를 해결하려면 무엇을해야합니까?
네, 이것은 '$ watch'와 같은 스코프의 api를 사용하는 테스트 컨트롤러에 대한 올바른 접근법입니다. – Vojta
"또한 jsTestDriver.conf 파일에 angular-mocks.js를로드해야합니다." 이것을 확장 할 수 있습니까? 이 .conf 파일은 어디에 있습니까? – cdmckay