-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Make toThrow matcher pass only if Error-like object is returned…
… from promises (#5670) * Fix rejects.not matcher * Check if resolved/rejected value is Error instance * Add test * Changelog * Change instanceof check * Add additional tests & update snaps * Add isError fn * Change err msg to also test partial string match * Move isError to expect utils * Add isError test * Update changelog
- Loading branch information
1 parent
aef82a2
commit 27a1dc6
Showing
7 changed files
with
231 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
/* eslint-env browser */ | ||
|
||
import {isError} from '../utils'; | ||
|
||
// Copied from https://github.com/graingert/angular.js/blob/a43574052e9775cbc1d7dd8a086752c979b0f020/test/AngularSpec.js#L1883 | ||
describe('isError', () => { | ||
function testErrorFromDifferentContext(createError) { | ||
const iframe = document.createElement('iframe'); | ||
document.body.appendChild(iframe); | ||
try { | ||
const error = createError(iframe.contentWindow); | ||
expect(isError(error)).toBe(true); | ||
} finally { | ||
iframe.parentElement.removeChild(iframe); | ||
} | ||
} | ||
|
||
it('should not assume objects are errors', () => { | ||
const fakeError = {message: 'A fake error', stack: 'no stack here'}; | ||
expect(isError(fakeError)).toBe(false); | ||
}); | ||
|
||
it('should detect simple error instances', () => { | ||
expect(isError(new Error())).toBe(true); | ||
}); | ||
|
||
it('should detect errors from another context', () => { | ||
testErrorFromDifferentContext(win => { | ||
return new win.Error(); | ||
}); | ||
}); | ||
|
||
it('should detect DOMException errors from another context', () => { | ||
testErrorFromDifferentContext(win => { | ||
try { | ||
win.document.querySelectorAll(''); | ||
} catch (e) { | ||
return e; | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters