0

i try to write unit tests for my Angular 2 App. I use Jasmine, Chutzpah in Visual Studio 2015. When the test dont have any dependencies or requirements then the test works. But when the test have one, then the Test will not be started.

In the output when i try to start the tests i get:

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

The Reference.js looks like:

/// <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" />

I think there is something wrong in this file or something is missing.

Bista
  • 7,869
  • 3
  • 27
  • 55
user3541236
  • 171
  • 2
  • 12

1 Answers1

0

As i thougth, the _Reference.js was not right. I changed to:

/// <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" />

The most Errors disappear, but 1 Error stays:

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

Could it be that i need an additional reference somehow?

Edit:

My app.component.spec.ts looks like:

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

And this .ts generates the 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
user3541236
  • 171
  • 2
  • 12