Установив необходимые пакеты (Chutzpah, Jasmine и Karma), я сделал простой Угловой тест, чтобы попробовать протестировать (поддерживаемый в проекте MVC), и у меня возникают проблемы с тестами.Угловые модульные тесты в Visual Studio с ошибкой
Когда я запускаю тесты в Карме из командной строки, они проходят. Когда я запускаю их через ReSharper/Chutzpah в Visual Studio, они терпят неудачу. Мои тесты запущены, но у меня возникают проблемы с пониманием ошибок.
MainCtrl.js:
var myModule = angular.module("MyApp", []);
myModule.controller("MainCtrl", ["$scope", function ($scope) {
$scope.addNum = function(x, y) {
return x + y;
}
$scope.fullName = function (x, y) {
return x + " " + y;
}
$scope.age = 29;
}]);
MainCtrlSpec.js:
/// <reference path="../../AngularTesting/Scripts/_references.js" />
describe("Controller: MainCtrl", function() {
beforeEach(module("MyApp"));
var MainCtrl, scope;
beforeEach(inject(function ($controller) {
scope = {};
MainCtrl = $controller("MainCtrl", {
$scope: scope
});
}));
it("should have scope defined", function() {
expect(scope).toBeDefined();
});
it("should add 2 numbers", function() {
expect(scope.addNum(5, 4)).toBe(9);
});
it("should have a name", function() {
expect(scope.fullName("Steve", "Jackson")).toBe("Steve Jackson");
});
it("should have an age of 29", function() {
expect(scope.age).toBe(29);
});
});
Karma.conf.js:
// Karma configuration
// Generated on Tue Jan 26 2016 13:05:20 GMT-0800 (Pacific Standard Time)
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'AngularTesting/Scripts/angular.js',
'AngularTesting/Scripts/angular-mocks.js',
'AngularTesting/ng-scripts/**.js',
'AngularTesting.Tests/ng-tests/**.js'
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
Когда я запускаю тесты в карме, все 4 проход , В VS Test Explorer он запускает отладчик Jasmine, но все 4 теста терпят неудачу. Я получаю следующие ошибки:
Error: ReferenceError: Can't find variable: angular (on line 1 of MainCtrl.js)
Error: Error: Bootstrap requires jQuery
Error: TypeError: undefined is not an object (evaluating '$.extend')
Error: TypeError: undefined is not an object (evaluating '$.validator')
получает также предупреждение:
Log Message: WARNING: Tried to load angular more than once.
Любая помощь с этими ошибками или предупреждения будут приветствоваться, спасибо.
может быть целесообразным разместить ваш karma.conf – sdfacre
@sdfacre добавил, спасибо за помощь – jacksonSD
просто убедитесь, что у вас есть те же js-зависимости, добавленные в раздел ссылок в chutzpah.json? – sdfacre