Skip to content

Does advice to avoid request assertions apply to server-side tests? #1682

Answered by kettanaito
thw0rted asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @thw0rted.

As a good place to start, I recommend reading through Request assertions. MSW generally discourages those since they often lead developers astray from testing what actually matters (the state/UI derived from the correct requests/responses).

If you are testing a service that's an intermediate layer and doesn't have any direct state to assert, then I recommend looking into Life-cycle events to track and assert the response, or implementing the following pattern:

import { DeferredPromise } from '@open-draft/deferred-promise'
import { server } from './your-msw-setup'

it('reformats the name parameter', async () => {
  const responseBodyPromise = new DeferredPromise()

  // Awai…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@thw0rted
Comment options

@kettanaito
Comment options

Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants