Jasmine,Chutzpah错误:ReferenceError:无法找到变量:require

时间:2017-02-07 13:45:53

标签: visual-studio-2015 jasmine chutzpah

我尝试为Angular 2 App编写单元测试。我在Visual Studio 2015中使用Jasmine,Chutzpah。当测试没有任何依赖关系或要求时,测试工作。但是当测试有一个时,测试将不会开始。

在我尝试开始测试的输出中,我得到:

Error: ReferenceError: Can't find variable: require at global code in ...\scripts\_references.js

Error: ReferenceError: Can't find variable: jQuery at global code in ...\scripts\_references.js

Reference.js看起来像:

/// <autosync enabled="true" />
/// <reference path="../gulpfile.js" />
/// <reference path="bootstrap.js" />
/// <reference path="jasmine.js" />
/// <reference path="jasmine/boot.js" />
/// <reference path="jasmine/console.js" />
/// <reference path="jasmine/jasmine.js" />
/// <reference path="jasmine/jasmine-html.js" />
/// <reference path="jasmine-html.js" />
/// <reference path="jasmine-samples/player.js" />
/// <reference path="jasmine-samples/playerspec.js" />
/// <reference path="jasmine-samples/song.js" />
/// <reference path="jasmine-samples/spechelper.js" />
/// <reference path="jquery.validate.js" />
/// <reference path="jquery.validate.unobtrusive.js" />
/// <reference path="jquery-1.10.2.js" />
/// <reference path="modernizr-2.6.2.js" />
/// <reference path="reflect.js" />
/// <reference path="respond.js" />
/// <reference path="ScriptsApp/app.component.spec.js" />
/// <reference path="shim.min.js" />
/// <reference path="system.src.js" />
/// <reference path="systemjs.config.js" />
/// <reference path="zone.js" />

我认为此文件中存在错误或缺少某些内容。

1 个答案:

答案 0 :(得分:0)

正如我所说,_Reference.js不对。我改为:

/// <autosync enabled="false" />

/// <reference path="node_modules\npm\node_modules\init-package-json\node_modules\promzard\test\exports.js" />


/// <reference path="jquery-1.10.2.js" />
/// <reference path="jquery.validate.js" />
/// <reference path="jquery.validate.unobtrusive.js" />

/// <reference path="jasmine.js" />
/// <reference path="jasmine/boot.js" />
/// <reference path="jasmine/console.js" />
/// <reference path="jasmine/jasmine.js" />
/// <reference path="jasmine/jasmine-html.js" />
/// <reference path="jasmine-html.js" />

/// <reference path="bootstrap.js" />
/// <reference path="modernizr-2.6.2.js" />
/// <reference path="reflect.js" />
/// <reference path="respond.js" />

/// <reference path="shim.min.js" />
/// <reference path="system.src.js" />
/// <reference path="systemjs.config.js" />
/// <reference path="zone.js" />

/// <reference path="ScriptsApp/app.component.spec.js" />

大多数错误消失,但仍有1个错误:

Error: ReferenceError: Can't find variable: require at global code in \scriptsapp\app.component.spec.js

难道我需要一个额外的参考吗?

修改

我的app.component.spec.ts看起来像:

import { AppComponent } from "./app.component.js";

describe('MyList Tests', () => {
	let list: AppComponent;
	let test: 0;

	beforeEach(() => {
		list = new AppComponent();
		test = 0;
	});

	it('Should 3 should be 5', () => {
		expect(list.hero.name.length).toBe(5);
		expect(5).toBe(3);
	});
});

这个.ts生成app.component.spec.js:

"use strict";
var app_component_js_1 = require("./app.component.js");
describe('MyList Tests', function () {
    var list;
    var test;
    beforeEach(function () {
        list = new app_component_js_1.AppComponent();
        test = 0;
    });
    it('Should 3 should be 5', function () {
        expect(list.hero.name.length).toBe(5);
        expect(5).toBe(3);
    });
});
//# sourceMappingURL=app.component.spec.js.map