Testing es2020 features with jest...
quick one liner:
git clone --depth=1 --no-single-branch https://github.com/daggerok/whats-new-in-es2020 app && cd $_ && npm i && npm t
mkdir app && cd $_
npm init -y
npm i -ED @babel/preset-env jest @jest/core @jest/globals @jest/types @types/jest @types/node
npm i -ED @jest/reporters jest-junit
package.json
{
"scripts": {
"dev": "npm run test -- --watchAll",
"test": "jest --reporters=default --reporters=jest-junit --collect-coverage"
}
}
npm i -ED @babel/preset-env core-js
package.json
{
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
}
test/some.test.js
import { describe, it, expect } from '@jest/globals';
describe('Dynamic Import', () => {
it('should import lazy module dynamically', async () => {
const dynamicModule = await import('../src/dynamic-module.js');
const total = await dynamicModule.sum(1, 2, 3);
await expect(total).toBe(6);
});
});
- https://jestjs.io/docs/en/tutorial-async#asyncawait
- https://github.com/facebook/jest/blob/master/examples/async/.babelrc.js
- https://jestjs.io/docs/en/cli
- https://www.freecodecamp.org/news/javascript-new-features-es2020/
- https://medium.com/@dtkatz/use-the-blazing-fast-parcel-bundler-to-build-and-test-a-react-app-e6972a2587e1