Skip to content

Instantly share code, notes, and snippets.

@ng-the-engineer
ng-the-engineer / README.md
Created January 17, 2021 16:44
Code snippet: Jest test not defined
➜  jest-with-typescript git:(main) ✗ npx jest
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/anthonyng/Repo/jest-with-typescript
  2 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 0 matches
  testPathIgnorePatterns: /node_modules/ - 2 matches
  testRegex:  - 0 matches
Pattern: - 0 matches
@ng-the-engineer
ng-the-engineer / dummy.test.ts
Last active January 17, 2021 16:53
Code snippet: dummy unit test
test("Dummy unit test", () => {
const actual = null; // not implemented yet
expect(actual).toBe(1);
});
@ng-the-engineer
ng-the-engineer / README.md
Created January 17, 2021 16:49
Code snippet: Failed unit test
➜  jest-with-typescript git:(main) ✗ npx jest
 FAIL  source/dummy.test.ts
  ✕ Dummy unit test (3 ms)

...

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots: 0 total
@ng-the-engineer
ng-the-engineer / dummy.ts
Created January 17, 2021 16:54
Code snippet: dummy ts function
export const sum = (a: number, b: number) => {
return a + b;
};
@ng-the-engineer
ng-the-engineer / dummy.test.ts
Created January 17, 2021 16:56
Code snippet: Dummy test.ts
import { sum } from "./dummy";
test("Dummy unit test", () => {
const actual = sum(1, 2);
expect(actual).toBe(3);
});
@ng-the-engineer
ng-the-engineer / README.md
Last active January 17, 2021 16:58
Code snippet: Test passed
➜  jest-with-typescript git:(main) ✗ npx jest
 PASS  source/dummy.test.ts
  ✓ Dummy unit test (1 ms)
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.526 s, estimated 2 s
Ran all test suites.
@ng-the-engineer
ng-the-engineer / jest.config.js
Created January 17, 2021 17:00
Code snippet: Jest config with roots
module.exports = {
// skipped other properties
roots: [
'<rootDir>/source/' // pointing to tests directory
]
};
@ng-the-engineer
ng-the-engineer / jest.config.js
Created January 17, 2021 17:02
Code snippet: Jest config with modulePathIgnorePatterns
module.exports = {
// skipped other properties
modulePathIgnorePatterns: [
"<rootDir>/build/"
]
};
@ng-the-engineer
ng-the-engineer / README.md
Created January 17, 2021 17:03
Code snippet: Jest with duplicated tests
PASS build/dummy.test.js
PASS source/dummy.test.ts
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 2.009 s
Ran all test suites.
@ng-the-engineer
ng-the-engineer / data.test.ts
Last active January 19, 2021 21:42
Code snipper: data.test.ts
import { fetch } from "./data";
it("returns name successfully", async () => {
const actual = await fetch();
expect(actual.data.name).toBe("Turksat 5A");
});