-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds "withMocks" test util to apply "setupServer" with handlers
- Loading branch information
1 parent
e69f867
commit 2449c35
Showing
2 changed files
with
21 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { RequestHandler } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
|
||
export async function withMocks( | ||
handlers: RequestHandler[], | ||
callback: () => Promise<any>, | ||
) { | ||
const server = setupServer(...handlers) | ||
server.listen() | ||
|
||
try { | ||
const result = await callback() | ||
return result | ||
} finally { | ||
server.close() | ||
} | ||
} |