unit test using typescript and karma -


i using karma, jasmine, typescript write unit test helloworld application https://angular.io/docs/js/latest/quickstart.html.

below test code:

///<reference path="../typings/jasmine/jasmine.d.ts"/>  import {     myappcomponent } '../spray1';  describe("name alice", () => {     var comp = new myappcomponent();      it("verify name", () => {         expect(comp.name).tobe("alice");      }); }); 

tsc (with "--module commonjs") transpiles test code into:

///<reference path="../typings/jasmine/jasmine.d.ts"/> var spray1_1 = require('../spray1'); describe("name alice", function () {     var comp = new myappcomponent_1.myappcomponent();     it("verify name", function () {         expect(comp.name).tobe("alice");     }); }); 

karma fails run unit test:

uncaught error: module name "../myappcomponent" has not been loaded yet context: _. use require([]) http://requirejs.org/docs/errors.html#notloaded @ /users/spray1/web2/node_modules/requirejs/require.js:141

chrome 43.0.2357 (mac os x 10.10.3): executed 0 of 0 success (0 secs / 0 secs)

if use tsc "--module amd", transpiled test code is:

define(["require", "exports", '../spray1'], function (require, exports, spray1_1) {     describe("name alice", function () {         var comp = new spray1_1.myappcomponent();         it("verify name", function () {             expect(comp.name).tobe("alice");         });     }); }); 

"karma start test/karma.conf.js" threw below error on transpiled js files:

uncaught error: mismatched anonymous define() module: function (require, exports, spray1_1) { describe("name alice", function () { var comp = new spray1_1.myappcomponent(); it("verify name", function () { expect(comp.name).tobe("alice"); }); }); } http://requirejs.org/docs/errors.html#mismatch @ /users/spray1/web2/node_modules/requirejs/require.js:141 chrome 43.0.2357 (mac os x 10.10.3): executed 0 of 0 error (0.04 secs / 0 secs)

as see, have trouble make work either way (--module commonjs/amd). way right way go , how make work? appreciate help!

so, link you've provided javascript version of quickstart, appears you're using typescript.

i suggest looking @ typescript version of quickstart documentation. has tsconfig.json file provides appropriate compile target:

{   "compileroptions": {     "target": "es5",     "module": "system",     "moduleresolution": "node",     "sourcemap": true,     "emitdecoratormetadata": true,     "experimentaldecorators": true,     "removecomments": false,     "noimplicitany": false   },   "exclude": [     "node_modules",     "typings/main",     "typings/main.d.ts"   ] } 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -