mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-31 00:16:47 +01:00
25 lines
542 B
TypeScript
25 lines
542 B
TypeScript
|
import { SetupServerApi, setupServer } from 'msw/node';
|
||
|
import { rest } from 'msw';
|
||
|
|
||
|
export const testServerSetup = (): SetupServerApi => {
|
||
|
const server = setupServer();
|
||
|
|
||
|
beforeAll(() => server.listen());
|
||
|
afterAll(() => server.close());
|
||
|
afterEach(() => server.resetHandlers());
|
||
|
|
||
|
return server;
|
||
|
};
|
||
|
|
||
|
export const testServerRoute = (
|
||
|
server: SetupServerApi,
|
||
|
path: string,
|
||
|
json: object
|
||
|
) => {
|
||
|
server.use(
|
||
|
rest.get(path, (req, res, ctx) => {
|
||
|
return res(ctx.json(json));
|
||
|
})
|
||
|
);
|
||
|
};
|