Jest.js

jestjs (41k ⭐) is an alternative to mocha. Both have roughly the same syntax to declare test suites.

Javascript

npm install --save-dev jest

Typescript

npm install --save-dev jest @types/jest ts-jest
npx ts-jest config:init

You can write your tests in any folder, but the filename must follow the pattern: name.test.js or name.test.ts.

// some test
test('xxx', () => {})
// some suite of tests
describe('xxx', () => {
    test('xxx', () => {})
    // ...
})

Usually, all tests are in a folder __tests__, and you will have multiple of these in your project.


Expect.js

Jest uses an alternative syntax of expect.

expect(xxx).toBeDefined()
expect(xxx).toBe(yyy)
// use not to negate something
expect(xxx).not.toBe(xxx)
expect(xxx).toEqual({ key: value })
expect(xxx).toStrictEqual({ key: value })
expect(xxx).toBeLessThanOrEqual(yyy)

πŸ‘» To-do πŸ‘»

Stuff that I found, but never read/used yet.