user4606322
user4606322

Reputation: 71

ES6 - how to test Jasime tests thru karma using ES6 like 'import' statement

I am new to javascript, trying to write a spec having an ES6 like import statement and then execute it thru Karma with pre-processors as traceur and browserify (to bundle and provide 'require' method). It continues to give me an error of invalid syntax and on looking at the specs file rendered in browser it looks that traceur never really processed the file.

This is the link to project on github -> https://github.com/gt-tech/es6-traceur-browserify-karma

I have also described the issue here as I am using that generator -> https://github.com/Swiip/generator-gulp-angular/issues/380

Upvotes: 1

Views: 5831

Answers (3)

TGH
TGH

Reputation: 39258

Here is an example of how to use ES6 to write unit tests. It's using Karma in combination with webpack:

http://www.syntaxsuccess.com/viewarticle/5532c5c0873cb5f0449ffcc5

Upvotes: 1

Public Profile
Public Profile

Reputation: 1837

I've been working on an example seed project to enable ES6 with karma/jasmine. As an example, I've added the TodoMVC app, with full tests, take a look:

https://github.com/lookfirst/systemjs-seed/

If you're going with ES6, forget about browsersify and traceur. Go with SystemJS and babel as they are the leaders in making this cutting edge stuff work properly.

Upvotes: 3

user4606322
user4606322

Reputation: 71

Issue is solved though not sure if it's the best way to solve it. Since we were trying to use "traceur" and "browserify" in a chained pre-processing we figured that for some reasons, they aren't really getting executed in a chain. Both of these processed the files (matching the path) independently messing up the eventual output. We took traceur out of equation and utilized "es6ify" transform within browserify to achieve transpilation and it worked like a breeze.

I am sure it's a beginner's question for many but hopefully it will help someone else taking their initial steps

Upvotes: 1

Related Questions