运行Visual Studio时,我进行了以下jasmine测试。
'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);
});
});
});当我尝试使用angular-mock函数时,问题似乎出现了。一旦我包含了任何beforeEach代码块,测试就不会运行,我得到的唯一消息是“遇到声明异常”。
我不确定我做错了什么,有什么建议吗?我检查了引用的文件的路径,它们都是正确的。
发布于 2019-10-03 22:26:29
在jest中,当我在describe中直接使用expect时,就会发生这种情况。应该在it内部调用expect (或它的别名,如xtest、test)
describe('a', () => {
expect(1).toEqual(0); /// encountered a declaration exception
it('b', () => {
expect(1).toEqual(0); /// works fine
});
});发布于 2015-02-09 14:26:07
发布于 2016-02-27 22:40:01
引用必须位于文件(https://stackoverflow.com/a/7003383/5409756)的顶部。我还建议创建一个包含所有引用的引用文件。这样,您只需在所有测试中包含一个文件。(How to reference multiple files for javascript IntelliSense in VS2010)
这应该是可行的:
///<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);
});
});
});
https://stackoverflow.com/questions/22692993
复制相似问题