-
-
Notifications
You must be signed in to change notification settings - Fork 969
Closed
Description
Describe the bug
CookieJar does not work in Jest test. I assume using util.promisify
for setCookie
causes this problem. https://github.com/sindresorhus/got/blob/master/source/request-as-event-emitter.ts#L40
I confirmed that it worked after I rewrote promisifying part like the below.
(cookie, url) => {
return new Promise((resolve, reject) => {
options.cookieJar.setCookie.call(
options.cookieJar,
cookie,
url,
(error, cookie) => {
if (error) { reject(error) }
else { resolve(cookie) }
}
)
})
}
- Node.js version: 10.14.0
- OS & version: macOS Mojave 10.14.4
Actual behavior
It should works like the example
Expected behavior
Throwing an error.
TypeError: cb is not a function
at next (node_modules/tough-cookie/lib/cookie.js:1090:9)
at MemoryCookieStore.Object.<anonymous>.MemoryCookieStore.putCookie (node_modules/tough-cookie/lib/memstore.js:124:3)
at withCookie (node_modules/tough-cookie/lib/cookie.js:1109:13)
at MemoryCookieStore.Object.<anonymous>.MemoryCookieStore.findCookie (node_modules/tough-cookie/lib/memstore.js:61:12)
at CookieJar.Object.<anonymous>.CookieJar.setCookie (node_modules/tough-cookie/lib/cookie.js:1113:9)
at Promise.all.rawCookies.map.rawCookie (node_modules/got/source/request-as-event-emitter.js:114:52)
at Array.map (<anonymous>)
Code to reproduce
import http from 'http'
import micro from 'micro'
import testListen from 'test-listen'
import got from 'got'
import { CookieJar } from 'tough-cookie'
import cookie from 'cookie'
describe('Cookies', () => {
it('selects cookies', async () => {
const server = new http.Server(
micro((req, res) => {
res.setHeader('set-cookie', cookie.serialize('message', 'yolo yolo'))
res.end('')
})
)
const url = await testListen(server)
const cookieJar = new CookieJar()
const res = await got.post(url, {
cookieJar
})
console.log(res.headers)
})
})
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.
k-yle
Metadata
Metadata
Assignees
Labels
No labels