Skip to content

Commit 0d3a2b3

Browse files
authored
Merge pull request #995 from wagenet/fix-reset-onerror
Correctly handle resetOnerror
2 parents 568833c + 3dfd676 commit 0d3a2b3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

addon-test-support/@ember/test-helpers/setup-onerror.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default function setupOnerror(onError?: (error: Error) => void): void {
4343

4444
/**
4545
* Resets `Ember.onerror` to the value it originally was at the start of the test run.
46+
* If there is no context or cached value this is a no-op.
4647
*
4748
* @public
4849
*
@@ -54,7 +55,13 @@ export default function setupOnerror(onError?: (error: Error) => void): void {
5455
* resetOnerror();
5556
* })
5657
*/
57-
export const resetOnerror: Function = setupOnerror;
58+
export function resetOnerror(): void {
59+
let context = getContext();
60+
61+
if (context && cachedOnerror.has(context)) {
62+
Ember.onerror = cachedOnerror.get(context);
63+
}
64+
}
5865

5966
/**
6067
* Caches the current value of Ember.onerror. When `setupOnerror` is called without a value

tests/unit/setup-ember-onerror-test.js

+5
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,10 @@ module('setupOnerror', function (hooks) {
6363
setupOnerror();
6464
}, /Must setup test context before calling setupOnerror/);
6565
});
66+
67+
test('resetOnerror does not raise an error without context', function (assert) {
68+
resetOnerror();
69+
assert.ok(true, 'nothing was thrown');
70+
});
6671
}
6772
});

0 commit comments

Comments
 (0)