mardi 2 février 2016

Jasmine Tests Failing in Visual Studio

I have Node, Chutzpah, Jasmine and Karma installed, and am testing an AngularJS app in Visual Studio 2015.

My tests are running but I am having trouble understanding the errors.

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);
    });
});

When I run the tests in karma, all 4 pass. In VS Test Explorer, it launches the Jasmine debugger but all 4 tests fail. I get the following errors:

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')

Also getting the warning:

Log Message: WARNING: Tried to load angular more than once.

Any help with these errors or warning would be welcomed, thank you.

Aucun commentaire:

Enregistrer un commentaire