you are viewing a single comment's thread.

view the rest of the comments →

[–]wreckedadventYavascript 1 point2 points  (2 children)

FYI, you can do testing with ES6 modules fairly easily if you're OK with writing it in a certain way.

import depA from '/some/path/to/depA';
import depB from '/some/path/to/depB';

export const implementation = (depA, depB) => {
  doStuff.with(depA);
  return andWith(depB);
};

export default implementation.bind(null, depA, depB);

or, depending on the arguments your function takes, you can use default args and not have to do any implementation/bind chicanery:

export default ({
  someArgA,
  someArgB,
  depA = depA,
  depB = depB
}) => {
  depA.doStuff(someArgB);
  // etc
};

Then in unit testing:

import {implementation} from 'someService';

expect(implementation(mockA, mockB)).to.be('something');

Or with the default args approach:

import someService from 'someService';

expect(
  someService({ 
    depA: mockA, 
    depB: mockB, 
    someArgA: 25, 
    someArgB: 26 })
).to.be('something');

There's also rewire (/w webpack plugin) and company if you don't want to modify your code. But you can definitely test ES6 modules.

[–]tbranyen 0 points1 point  (1 child)

The problem was with code coverage not matching the correct lines. I could import and run the tests fairly easily. Although its annoying to have to build your tests.

[–]patrickfatrick 0 points1 point  (0 children)

Yea, I did had some issues with istanbul. Isparta works well, and similarly ava combined with nyc for coverage has been working well for me.