🧪 Jest

👋 FYI, this note is over 6 months old. Some of the content may be out of date.
On this page

Basic test skeleton Jump to heading

describe('Given a xxx', () => {
describe('when it is rendered', () => {
test('it should ', () => {
// Arrange

// Act

// Assert
expect(true).toBe(true)
})
})
})

Use Jest globals Jump to heading

import { expect, test } from '@jest/globals'

test('two plus two is four', () => {
expect(2 + 2).toBe(4)
})

Throw Jump to heading

import { formatDate } from './formatDate'

test('it should throw', () => {
expect(() => formatDate('197901180')).toThrow(
'Date string wrong format/length'
)
expect(() => formatDate('abcdefgh')).toThrow(
'Date string must be only digits'
)
})

← Back home