Skip to content

Commit

Permalink
Add {get,set}CookieValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Oct 27, 2015
1 parent e447b6f commit 7721cfa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/browser/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ exports.clearCookies = function clearCookies() {
return this.deleteAllCookies();
};

exports.setCookieValue = function setCookieValue(name, value, options) {
var cookie = _.extend({
name: name,
value: value,
path: '/',
secure: false,
}, options || {});
return this.setCookie(cookie);
};

exports.getCookieValue = function getCookieValue(name) {
return this.getCookie(name).then(_.property('value'));
};

exports.setCookies = function setCookies(cookies) {
return Bluebird.all(cookies.map(this.setCookie, this));
};
Expand Down
18 changes: 18 additions & 0 deletions test/integration/cookie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,22 @@ describe('cookie', () => {
const cookie = await browser.getCookie('test_cookie');
assert.falsey(cookie);
});

describe('setCookieValue', () => {
before(() =>
browser
.navigateTo('/some/nested/url')
.setCookie({ name: 'non_root', value: 'a' })
.setCookieValue('root', 'b')
.navigateTo('/'));

it('can\'t read the non-root cookie', async () => {
assert.falsey(await browser.getCookie('non_root'));
});

it('can read the root cookie', async () => {
assert.truthy(await browser.getCookie('root'));
assert.equal('b', await browser.getCookieValue('root'));
});
});
});

0 comments on commit 7721cfa

Please sign in to comment.