Last active
September 26, 2018 14:34
-
-
Save smolak/d12b893efa377ce9f920d58171581c7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('executing handlers', () => { | |
context('for synchronous handlers', () => { | |
it('should happen in sequence', async () => { | |
const hook1 = { | |
event: 'preEventName', | |
handler: sinon.spy() | |
}; | |
const hook2 = { | |
event: 'preEventName', | |
handler: sinon.spy() | |
}; | |
cacheInstance.addHooks([ hook1, hook2 ]); | |
await getPreData('eventName', anyValidArgs); | |
expect(hook1.handler).to.have.been.calledBefore(hook2.handler); | |
}); | |
}); | |
context('for asynchronous handlers', () => { | |
it('should happen in sequence', async () => { | |
const stallFor = async (time) => await new Promise(resolve => setTimeout(resolve, time)); | |
const spyForSlowHandler = sinon.spy(); | |
const hook1 = { | |
event: 'preEventName', | |
handler: async () => { | |
await stallFor(50); | |
spyForSlowHandler(); | |
} | |
}; | |
const hook2 = { | |
event: 'preEventName', | |
handler: sinon.spy() | |
}; | |
cacheInstance.addHooks([ hook1, hook2 ]); | |
await getPreData('eventName', anyValidArgs); | |
expect(spyForSlowHandler).to.have.been.calledBefore(hook2.handler); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment