Skip to content

Commit 8d6db7b

Browse files
better error handling in tests
1 parent 8728edb commit 8d6db7b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tests/fixtures/helper.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@
2121
/**
2222
* Throws an error if called.
2323
*/
24-
helper.shouldNotGetCalled = function shouldNotGetCalled() {
25-
throw new Error('This function should not have gotten called.');
26-
};
24+
helper.shouldNotGetCalled = function shouldNotGetCalled(done) {
25+
var err = new Error('This function should not have gotten called.');
26+
if (typeof done === 'function') {
27+
return function(err2) {
28+
if (err2 instanceof Error) {
29+
done(err2);
30+
}
31+
else {
32+
done(err);
33+
}
34+
}
35+
}
36+
else {
37+
throw err;
38+
}
39+
};
2740

2841
/**
2942
* Tests the {@link $RefParser.resolve} method,
@@ -73,7 +86,7 @@
7386

7487
done();
7588
})
76-
.catch(helper.shouldNotGetCalled);
89+
.catch(helper.shouldNotGetCalled(done));
7790
}
7891
};
7992

0 commit comments

Comments
 (0)