Closed kemalcany closed 9 years ago
Hi @kemalcany
Two things I've noticed:
System.import('addition')
to System.import('addition.js')
.
You could also use System.defaultJSExtensions = true;
, but I wouldn't recommend it because it's only there for backwards compatibility.System.import()
, which returns promise for when the import has completed. However your test assumes that add()
is available straight away.
You can either wrap your test code in .then()
, or change to a synchronous method like require()
or ES6 import
notation.Hope that helps.
Hi @rolaveric thanks so much for your help!
But require() worked! :) I guess it was an issue of synchronizing as you've suggested. Thanks a lot for that!!!
I am copy/pasting the working code below for future reference.
src/js/addition.js
function add(a,b){
return a + b;
}
module.exports.add = add;
src/test/test.js
var addition = require("src/js/addition.js");
describe("Addition", function() {
it("gets loaded and adds two numbers", function() {
expect(addition.add(3,4)).toBe(7);
});
});
No changes in karma.conf.js
Cheers!
Hello guys..
This is going to be a total noob problem but I've spent a lot of time on configuring Karma to work with System.js and so far no luck. Wanted to ask for help before I switch to a different module plugin...
All I am trying to achieve now is to load (via System.import) an external .js file to my Karma run and use a function there. The test and .js is trivial:
src/js/addition.js
src/test/test.js
When Karma runs the test it cannot find the add function defined under addition.js. It also gives a 404 warning as follows:
... 19 11 2015 09:27:48.999:WARN [web-server]: 404: /base/addition
Clearly, I can't load addition.js inside the test.js
My karma.conf.js file is as follows:
Notice that I am not using a config file for system.js and instead loading paths under systemjs in karma.conf.js
Can anyone tell me what I am doing wrong please? Hope this will be a good place for other starters to take advantage too..
Cheers!