So, I'm testing a TypeScript file with Mocha, I access a dependency in the file via import, and the function to test is in the same file, like below:
import { Foo } from 'foo-library';
// I'm trying to test this
export const myHelperFunction = (a, b) => {
return a + b;
// Foo not used
};
export class BigClass {
public doStuff() {
// uses Foo
}
}
Then I have my test file:
import { myHelperFunction } from './my-file';
it('does the right thing', () => {
expect(myHelperFunction(2, 3)).to.equal(5);
});
Now, Mocha tries to parse foo-library contents while attempting to execute tests, and throws an error that says "unexpected token import", even though the import is not used in myHelperFunction. The file is in ES6 format and Mocha/Node is unable to parse it correctly.
Should the dependency files be transpiled to ES5 somehow? Is it possible to skip the imports altogether while testing? I have tried to mock the imports with several libraries (Sinon etc.) and that hasn't worked either.
I'd greatly appreciate any ideas.