Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

jest test async code

### Notes

- Add `async` to the function that gets passed to the test - Use `await` when calling the function under test - Make the function under test `async` - Add `await` as necessary in the function under test

### Test file

Code

const sum = require('./sum')

test('adds 1 + 2 to equal 3', async () => {
  const result = await sum(1, 2)
  expect(result).toBe(3)
})

### File under test

Code

async function sum(a, b) {
  // do some 'await' stuff here
  return a + b
}

module.exports = sum