Skip to content

Instantly share code, notes, and snippets.

@ideadapt
Last active May 22, 2016 21:44
Show Gist options
  • Save ideadapt/1d14e11841de3ede13a89d0d5e52c835 to your computer and use it in GitHub Desktop.
Save ideadapt/1d14e11841de3ede13a89d0d5e52c835 to your computer and use it in GitHub Desktop.
jasmine done callback behaviour
describe('experiments with done', ()=>{
describe('- correct usage -', ()=>{
it('should fail because of async expect failure, and failure is assigned to correct spec', (done)=>{
new Promise(function(res, rej){
setTimeout(res, 1000)
}).then(()=>{
expect(1).toEqual(11)
}).catch().then(done)
})
it('should wait for async done call', (done)=>{
new Promise(function(res, rej){
setTimeout(res, 1000)
}).then(()=>{
expect(4).toEqual(4)
done()
})
})
it('should wait for async done call, but fails meanwhile', (done)=>{
new Promise(function(res, rej){
setTimeout(res, 1000)
}).then(()=>{
expect(4).toEqual(44)
done()
})
})
it('should wait for async done call, which is at the end of the promise chain', (done)=>{
new Promise(function(res, rej){
setTimeout(res, 1000)
}).then(()=>{
expect(1).toEqual(1)
}).catch().then(done)
})
})
describe('- incorrect usage -', ()=>{
it('should fail because of async expect failure, but wont since done not used', ()=>{
new Promise(function(res, rej){
// this expect throws an error, which jasmine is handling while already processing a succeeding spec.
// hence the error will be assigned to that wrong spec.
setTimeout(res, 1000)
}).then(()=>{
expect(2).toEqual(22)
})
})
it('should fail with failed expect from previous spec', (done)=>{
// most likely the failed expectation from previous spec will be detected and reported here.
new Promise(function(res, rej){
setTimeout(res, 1000)
}).then(done)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment