Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jasmine encountered a declaration exception

Running Visual Studio I have the following jasmine test.

'use strict';

///<reference path="jasmine.js"/>
///<reference path="../../Scripts/angular.min.js"/>
///<reference path="../../Scripts/angular-route.min.js"/>
///<reference path="../../Scripts/angular-mocks.js"/>
///<reference path="../application.js"/>

describe('StatusPage Tests', function () {
    describe('Application Functions', function () {
        var location;

        beforeEach(module("StatusApplication"));

        beforeEach(inject(function($location) {
            location = $location;
        }));

        it('DetermineRootUrl_Application_RootUrl', function () {
            var result = DetermineRootUrl(location);

            var expectedResult = 'https://localhost/OK59SP1/';
            expect(expectedResult).toBe(expectedResult);
        });
    });
});

the problem seems when I try and use a angular-mock function. as soon as I include any of the beforeEach code blocks the test does not run and the only message I get back is "encountered a declaration exception"

I am not sure what I am doing wrong here, any suggestions? I checked the paths to the files referenced and they are correct.

like image 421
user3469358 Avatar asked Mar 27 '14 16:03

user3469358


3 Answers

This happened for me in jest when I used expect directly inside describe. expect should be called inside it (or whatever alias it has like xtest, test)

describe('a', () => {
   expect(1).toEqual(0); /// encountered a declaration exception

   it('b', () => {
      expect(1).toEqual(0); /// works fine
   });
});
like image 165
Orkhan Alikhanov Avatar answered Sep 25 '22 12:09

Orkhan Alikhanov


Check this out: Testacular: encountered a declaration exception

Try including angular-mocks.js in your config file

like image 33
Lev Kazakov Avatar answered Sep 24 '22 12:09

Lev Kazakov


The references must be on top of the file (https://stackoverflow.com/a/7003383/5409756). I recommend also to create a references file with all references included. This way you have only to include one file in all the tests. (How to reference multiple files for javascript IntelliSense in VS2010)

This should work:

///<reference path="jasmine.js"/>
///<reference path="../../Scripts/angular.min.js"/>
///<reference path="../../Scripts/angular-route.min.js"/>
///<reference path="../../Scripts/angular-mocks.js"/>
///<reference path="../application.js"/>

'use strict';

describe('StatusPage Tests', function () {
    describe('Application Functions', function () {
        var location;

        beforeEach(module("StatusApplication"));

        beforeEach(inject(function($location) {
            location = $location;
        }));

        it('DetermineRootUrl_Application_RootUrl', function () {
            var result = DetermineRootUrl(location);

            var expectedResult = 'https://localhost/OK59SP1/';
            expect(expectedResult).toBe(expectedResult);
        });
    });
});
like image 23
kobL Avatar answered Sep 24 '22 12:09

kobL