Skip to content

Commit

Permalink
test(cookies-request): remove ".end()" when using "https.get"
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Nov 10, 2021
1 parent f6fbd6c commit fe6751f
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions test/msw-api/setup-server/scenarios/cookies-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,33 @@ afterAll(async () => {
})

test('has access to request cookies', (done) => {
let resBody = ''
let responseBody = ''
const url = new URL(httpServer.https.makeUrl('/user'))

https
.get(
{
method: 'GET',
protocol: url.protocol,
host: url.host,
path: url.pathname,
headers: {
Cookie: 'auth-token=abc-123',
},
https.get(
{
method: 'GET',
protocol: url.protocol,
host: url.host,
path: url.pathname,
headers: {
Cookie: 'auth-token=abc-123',
},
(res) => {
res.setEncoding('utf8')
res.on('error', done)
res.on('data', (chunk) => (resBody += chunk))
res.on('end', () => {
const resJsonBody = JSON.parse(resBody)
expect(resJsonBody).toEqual({
cookies: {
'auth-token': 'abc-123',
},
})

done()
},
(res) => {
res.setEncoding('utf8')
res.on('error', done)
res.on('data', (chunk) => (responseBody += chunk))
res.on('end', () => {
const json = JSON.parse(responseBody)
expect(json).toEqual({
cookies: {
'auth-token': 'abc-123',
},
})
},
)
.end()

done()
})
},
)
})

0 comments on commit fe6751f

Please sign in to comment.