Skip to content

Instantly share code, notes, and snippets.

@Maurifc
Last active January 4, 2023 18:10
Show Gist options
  • Save Maurifc/e01dc0b9207eac694ec98c395498aa3c to your computer and use it in GitHub Desktop.
Save Maurifc/e01dc0b9207eac694ec98c395498aa3c to your computer and use it in GitHub Desktop.
nodejs - Boiler plate of a test.js file (jest)
/* eslint-disable no-undef */
import { jest } from '@jest/globals'
// run before all tests (setup)
beforeAll(async () => {
// setup the test environment
// mock
})
// run before each test
beforeEach(async () => {
jest.clearAllMocks()
})
describe('utils/sum.js', () => {
describe('sum function', () => {
test('Should return the sum of two numbers', async () => {
const sum = (num1, num2) => { return num1 + num2 }
expect(sum(2, 3)).toBe(5)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment