
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
msw-when-then
Advanced tools
MSW is a brilliant tool for mocking, but is missing a few things to make it perfect for testing. msw-when-then aims to help with that.
when-then
style Apinpm install msw-when-then
server
and rest
:import { whenThen, get, ok } from "msw-when-then";
const { when } = whenThen(server, rest);
when(get("https://some.url")).thenReturn(ok({ foo: "bar" }));
Familiar chaining pattern, the responses are return in order with the last response returned for all subsequent requests.
import { get, badRequest, ok } from "msw-when-then";
when(get("https://some.url"))
.thenReturn(badRequest({ response: "first request" }))
.thenReturn(ok({ response: "subsequent requests" }));
Sometimes you need to take things into your own hands. We expose the original MSW resolver function, so you can do whatever you like. See MSW Docs for more details.
import { get } from "msw-when-then";
when(get("https://some.url")).then((req, res, ctx) => {
// Any additional logic here
return res(ctx.status(400), ctx.json({ response: "last response" }));
});
Mocking APIs is great, but how can we ensure our app is sending the right data? We can do this by specifying the expected request data when mocking.
Note: The id
key in the withParams
here matches the :id
argument in the post
url
import { post, request, withBody, withHeaders, withParams, ok } from "msw-when-then";
when(post("https://some.url/:id")).thenReturnFor(
request(
withBody({ foo: "bar" }),
withHeaders({ "content-type": "application/json" }),
withParams({ id: "expected-id" })
),
ok({ response: "success" })
);
FAQs
A non-invasive 'when-then' style API for MSW
We found that msw-when-then demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.