Skip to content

Instantly share code, notes, and snippets.

@rcollette
rcollette / msw-post-expectation.ts
Created August 1, 2025 12:55
Mock Service Worker Post Expectation with Sinon
// msw-utils.ts
import { rest, RestHandler } from 'msw'
import { afterEach } from 'vitest'
import sinon from 'sinon'
/**
* Creates an MSW POST handler that will throw in afterEach
* if the actual request body doesn’t deep-equal the expected one,
* using Sinon for comparison.
*/