How to write unit tests supporting Javascript 6 modules -


my javascript codebase based on new es6 modules.

so have javascript files example:

export class myclass {   constructor() {     this.list = [];   }    add(el) { this.list.push(el); } } 

as module, import file in other javascript files this:

import * lists "./myclass"; 

and inside html page, following syntax has used:

<script src="myclass.js" type="module"></script> 

unit testing

i need framework testing code. problem using javascript 6 modules, modern frameworks karma have problems import files not modules:

module.exports = function(config) {   config.set({     files: [       'src/**/*.js',       'test/**/*.js'     ],     ...   }) } 

above example of karma.conf.js. in specific case of karma, runner not import files modules, injection in page fails.

what unit test frameworks can use testing javascript 6 modules?

you can check out jest, it's facebook's test framework allows run tests on node (with jsdom).

it runs tests in parallel , without browser, therefore suppose faster.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -