diff --git a/docs/api/cookies.md b/docs/api/cookies.md index 417b48867834..d56af39ced35 100644 --- a/docs/api/cookies.md +++ b/docs/api/cookies.md @@ -84,7 +84,7 @@ the response. #### `cookies.set(details)` * `details` Object - * `url` String - The url to associate the cookie with. + * `url` String - The url to associate the cookie with. An error is thrown if the url is invalid. * `name` String (optional) - The name of the cookie. Empty by default if omitted. * `value` String (optional) - The value of the cookie. Empty by default if omitted. * `domain` String (optional) - The domain of the cookie; this will be normalized with a preceding dot so that it's also valid for subdomains. Empty by default if omitted. diff --git a/spec-main/api-session-spec.js b/spec-main/api-session-spec.js index ff9023a15b7c..e1da8c5d42ca 100644 --- a/spec-main/api-session-spec.js +++ b/spec-main/api-session-spec.js @@ -88,12 +88,23 @@ describe('session module', () => { }) it('yields an error when setting a cookie with missing required fields', async () => { - await expect((async () => { - const { cookies } = session.defaultSession - const name = '1' - const value = '1' - await cookies.set({ url: '', name, value }) - })()).to.eventually.be.rejectedWith('Failed to get cookie domain') + const { cookies } = session.defaultSession + const name = '1' + const value = '1' + + await expect( + cookies.set({ url: '', name, value }) + ).to.eventually.be.rejectedWith('Failed to get cookie domain') + }) + + it('yields an error when setting a cookie with an invalid URL', async () => { + const { cookies } = session.defaultSession + const name = '1' + const value = '1' + + await expect( + cookies.set({ url: 'asdf', name, value }) + ).to.eventually.be.rejectedWith('Failed to get cookie domain') }) it('should overwrite previous cookies', async () => {