Testing TypeScript code with Jasmine
masterJasmine can be used to test TypeScript code, but because the TypeScript ecosystem is fragmented, there is no single configuration that works for all projects. The setup depends on your TypeScript dialect and build tooling.
Common strategies include:
- Module Load-time Translation: Using a Node module loader (like
@babel/registerortsx) to translate TypeScript to JavaScript as modules are loaded. This is fast but lacks type checking. - Node Native Support: Using Node's built-in ability to run TypeScript (available in newer Node versions). This is the least setup but has specific syntax and import requirements.
- Pre-compilation: Compiling TypeScript to JavaScript files on disk using
tscbefore running Jasmine. This provides type checking but has a slower edit-compile-run cycle. - Web Test Runner: Using Web Test Runner with the
esbuildplugin andweb-test-runner-jasmine.