Add specs for cookie changed event
This commit is contained in:
parent
19c7ee0932
commit
d83534d513
1 changed files with 45 additions and 0 deletions
|
@ -179,6 +179,51 @@ describe('session module', function () {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('changed events', function () {
|
||||
it('emits an event when a cookie is set', function (done) {
|
||||
session.defaultSession.cookies.on('changed', function cookieChanged(event, cookie, cause, removed) {
|
||||
if (cookie.name !== 'foo') return
|
||||
|
||||
assert.equal(cookie.name, 'foo')
|
||||
assert.equal(cookie.value, 'bar')
|
||||
assert.equal(cause, 'explicit')
|
||||
assert.equal(removed, false)
|
||||
session.defaultSession.cookies.removeListener('changed', cookieChanged)
|
||||
done()
|
||||
})
|
||||
session.defaultSession.cookies.set({
|
||||
url: url,
|
||||
name: 'foo',
|
||||
value: 'bar'
|
||||
}, function (error) {
|
||||
if (error) return done(error)
|
||||
})
|
||||
})
|
||||
|
||||
it('emits an event when a cookie is removed', function (done) {
|
||||
session.defaultSession.cookies.on('changed', function cookieChanged(event, cookie, cause, removed) {
|
||||
if (cookie.name !== 'foo' || removed == false) return
|
||||
|
||||
assert.equal(cookie.name, 'foo')
|
||||
assert.equal(cookie.value, 'bar')
|
||||
assert.equal(cause, 'overwrite')
|
||||
assert.equal(removed, true)
|
||||
session.defaultSession.cookies.removeListener('changed', cookieChanged)
|
||||
done()
|
||||
})
|
||||
session.defaultSession.cookies.set({
|
||||
url: url,
|
||||
name: 'foo',
|
||||
value: 'bar'
|
||||
}, function (error) {
|
||||
if (error) return done(error)
|
||||
session.defaultSession.cookies.remove(url, 'foo', function (error) {
|
||||
if (error) return done(error)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('ses.clearStorageData(options)', function () {
|
||||
|
|
Loading…
Reference in a new issue