Testing with Callbacks

Learn how to use Jest to test asynchronous code with callbacks.

The callback pattern

A callback is a function that is passed as the last argument to another function and called at the end of that function. It looks something like this:

function logger(str) {
  console.log(str);
}

function getUserName(user, callback) {
  const { name } = user;

  callback(name);
}

getUserName(
...