Commit e68aa1ab authored by Robert Knight's avatar Robert Knight

Fix AnnotationController#delete test failure

Fix a test failure due to a subtle issue with the interaction between
the `$q` service, `AnnotationController#delete` and `$timeout.flush` in
tests.

Instantiating the rejected promise _before_ calling `$timeout.flush`
resulted in Angular's unhandled promise checking code being triggered
in the test.
parent 9d73f6d2
......@@ -710,8 +710,13 @@ describe('annotation', function() {
it('flashes an error if the delete fails on the server', function(done) {
var controller = createDirective().controller;
sandbox.stub($window, 'confirm').returns(true);
var err = new Error('500 Server Error');
fakeAnnotationMapper.deleteAnnotation.returns($q.reject(err));
fakeAnnotationMapper.deleteAnnotation = sinon.spy(() => {
// nb. we only instantiate the rejected promise when
// `deleteAnnotation` is called to avoid triggering `$q`'s unhandled
// promise rejection handler during the `$timeout.flush()` call.
return $q.reject(new Error('500 Server Error'));
});
controller.delete().then(function() {
assert.calledWith(fakeFlash.error,
'500 Server Error', 'Deleting annotation failed');
......
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