Set up MSW

With MSW set up, we can now run npm test and see the outgoing request's method and URL printed during the test run:
$ npm test

> test
> vitest

stdout | get-auth-token.test.ts > returns the authentication token on successful authentication
POST https://api.example.com/auth

 ❯ get-auth-token.test.ts (1)
   Γ— returns the authentication token on successful authentication
This confirms that MSW can intercept the request made in getAuthToken(). But the test itself is still failing!
Caused by: Error: getaddrinfo ENOTFOUND api.example.com
Although the error is caused by requesting a non-existent URL, the real issue is that we're still allowing the test to make the actual request.
That's right, MSW operates in pass-through mode by default, allowing all intercepted requests to proceed unless instructed otherwise.
It is time for us to change that by mocking the request with MSW!

Access Denied

You must login or register for the workshop to view the diff.

Check out this video to see how the diff tab works.