-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test for 204 http status | 379
- Loading branch information
avivasyuta
committed
Sep 1, 2023
1 parent
ca14782
commit 018eebe
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
test/modules/XMLHttpRequest/response/xhr-response-with-empty-body.browser.test.ts
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,45 @@ | ||
import { Page } from '@playwright/test' | ||
import { HttpServer } from '@open-draft/test-server/http' | ||
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest' | ||
import { test, expect } from '../../../playwright.extend' | ||
import { useCors } from '../../../helpers' | ||
|
||
declare namespace window { | ||
export const interceptor: XMLHttpRequestInterceptor | ||
export let serverHttpUrl: string | ||
export let serverHttpsUrl: string | ||
} | ||
|
||
const httpServer = new HttpServer((app) => { | ||
app.use(useCors) | ||
app.get('/', (req, res) => { | ||
res.status(200).json({ route: '/' }) | ||
}) | ||
app.get('/get-204', (req, res) => { | ||
res.status(204).send() | ||
}) | ||
}) | ||
|
||
test.beforeAll(async () => { | ||
await httpServer.listen() | ||
}) | ||
|
||
test.afterAll(async () => { | ||
await httpServer.close() | ||
}) | ||
|
||
test('204 http status', async ({ | ||
loadExample, | ||
callRawXMLHttpRequest, | ||
}) => { | ||
await loadExample(require.resolve('./xhr.browser.runtime.js')) | ||
|
||
const secondResponse = await callRawXMLHttpRequest({ | ||
method: 'GET', | ||
url: httpServer.http.url('/get-204'), | ||
}) | ||
|
||
expect(secondResponse.status).toBe(204) | ||
expect(secondResponse.statusText).toBe('No Content') | ||
expect(secondResponse.body).toEqual('') | ||
}) |