JavaScript new features es2020
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);
});
});