Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daggerok/jest-typescrip-tests
Testing TypeScript code using jest
https://github.com/daggerok/jest-typescrip-tests
jest jest-tests jest-typescript ts-jest typescript
Last synced: 5 days ago
JSON representation
Testing TypeScript code using jest
- Host: GitHub
- URL: https://github.com/daggerok/jest-typescrip-tests
- Owner: daggerok
- Created: 2020-05-07T20:23:13.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-07T20:23:28.000Z (over 4 years ago)
- Last Synced: 2024-11-11T15:39:22.958Z (2 months ago)
- Topics: jest, jest-tests, jest-typescript, ts-jest, typescript
- Language: TypeScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jest typescript [![Build Status](https://travis-ci.org/daggerok/jest-typescrip-tests.svg?branch=master)](https://travis-ci.org/daggerok/jest-typescrip-tests)
Testing TypeScript code using jest...## jest es++ typescript..
```bash
mkdir app && cd $_
npm init -y
npm i -ED jest @jest/core @jest/globals @jest/types @types/node @babel/preset-env core-js @babel/preset-typescript typescript ts-jest @types/jest
```_package.json_
```json
{
"scripts": {
"dev": "npm run test -- --watchAll",
"test": "jest --preset=ts-jest --testEnvironment=node ...",
"test-js-with-ts": "jest --preset=ts-jest/presets/js-with-ts ...",
"test-js-with-babel": "jest --preset=jest --preset=ts-jest/presets/js-with-babel ..."
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-typescript"
]
}
}
```## jest reporters
```bash
npm i -ED @jest/reporters jest-junit
```_package.json_
```json
{
"scripts": {
"test": "jest --reporters=default --reporters=jest-junit --collect-coverage ..."
}
}
```## testing
add _src/dynamic-module.ts_ file:
```ts
export const sum = (...args): number =>
args.reduce((prev, curr) => prev + curr, 0);
```add _test/dynamic-import.test.ts_ file:
```ts
import { expect, it } from '@jest/globals';it('should import dynamic lazy module', async () => {
const dynamicModule: any = await import('../src/dynamic-module');
const total: any = await dynamicModule.sum(1, 2, 3);
await expect(total).toBe(6);
});
```## finally, execute
```bash
npm t
npm run test-js-with-ts
npm run test-js-with-babel
```or simply use quick one liner for github repo starter:
```bash
git clone --depth=1 --no-single-branch https://github.com/daggerok/jest-typescrip-tests app && cd $_ && npm i && npm t
```## resources
* https://kulshekhar.github.io/ts-jest/user/config/
* https://kulshekhar.github.io/ts-jest/user/install
* https://jestjs.io/docs/en/next/getting-started#using-typescript
* 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