Commit 29fd17c6 authored by Nick Stenning's avatar Nick Stenning

Improve error handling in test that uses setTimeout

If one of these asserts fails, then this test will timeout (taking 2
seconds to do so).

By using a small helper (`timeoutPromise`) to implement the "next tick"
functionality that was previously achieved with `setTimeout`, this is
improved: we return a promise from the test function and a failure will
be reported immediately.

See https://mochajs.org/#working-with-promises for more on returning
promises from mocha test functions.
parent b4653a0e
......@@ -19,6 +19,10 @@ Guest = proxyquire('../guest', {
'scroll-into-view': scrollIntoView,
})
# A little helper which returns a promise that resolves after a timeout
timeoutPromise = (millis = 0) ->
new Promise((resolve) -> setTimeout(resolve, millis))
describe 'Guest', ->
sandbox = sinon.sandbox.create()
CrossFrame = null
......@@ -215,18 +219,20 @@ describe 'Guest', ->
assert.isTrue(event.isPropagationStopped())
describe 'createAnnotation()', ->
it 'adds metadata to the annotation object', (done) ->
it 'adds metadata to the annotation object', ->
guest = createGuest()
sinon.stub(guest, 'getDocumentInfo').returns(Promise.resolve({
metadata: {title: 'hello'}
uri: 'http://example.com/'
}))
annotation = {}
guest.createAnnotation(annotation)
setTimeout ->
timeoutPromise()
.then ->
assert.equal(annotation.uri, 'http://example.com/')
assert.deepEqual(annotation.document, {title: 'hello'})
done()
it 'treats an argument as the annotation object', ->
guest = createGuest()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment