Reputation: 10154
Unfurtunately, our web project doesn't use ES6 modules yet. Instead, we transpile our TypeScript sources and then concatenate them all together.
This works well in the browser, and also in Karma and WallabyJS (by setting the files
option in their configuration file).
Since our 1500 tests takes a long time to execute, I wanted to check Jest. However, our tests fail because jest can't find the types we are importing.
For instance, we have a class named StringUtils
and the for the following code:
import StringUtils = common.utils.StringUtils;
class Person {
private _name: string;
address(): string {
return StringUtils.buildAddress(this);
}
}
We fail with:
ReferenceError: common is not defined
Is there a way to tell jest what files to load (and in what order) before running tests, like we do with Karma and WallabyJS?
Upvotes: 1
Views: 1303
Reputation: 26547
You should be able to specify a setupTestFrameworkScriptFile or [setupFiles]([setupTestFrameworkScriptFile](https://facebook.github.io/jest/docs/configuration.html#setupFiles] which will let you setup some stuff before it starts running your tests.
You would put those in your package.json
, or a separate file (if you pass it in with a --config
flag).
Upvotes: 1