Created
April 28, 2026 15:46
-
-
Save kettanaito/6f5319902918ff17af0eb2fbd9a129cb to your computer and use it in GitHub Desktop.
msw-435
This file contains hidden or 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
| import { http, HttpResponse } from 'msw' | |
| import { setupServer } from 'msw/node' | |
| const server = setupServer( | |
| http.get('https://example.com/set-cookie', () => { | |
| return new HttpResponse(null, { | |
| headers: { | |
| 'set-cookie': | |
| 'key=value; HttpOnly; Max-Age=86400; Path=/; SameSite=None; Secure', | |
| }, | |
| }) | |
| }), | |
| http.get('https://example.com/require-cookie', ({ request, cookies }) => { | |
| console.log('parsed cookies:', cookies) | |
| if ( | |
| request.headers.get('cookie') === | |
| 'key=value; Max-Age=86400; Path=/; Secure; HttpOnly; key=value; Max-Age=86400; Path=/; Secure; HttpOnly' | |
| ) { | |
| return new Response(null, { status: 204 }) | |
| } | |
| return new Response(null, { status: 400 }) | |
| }), | |
| ) | |
| server.listen() | |
| await fetch('https://example.com/set-cookie') | |
| await fetch('https://example.com/require-cookie').then((response) => { | |
| console.log(response.status) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment