fix #1252
This commit is contained in:
@@ -65,6 +65,30 @@ describe("toThrowError", function() {
|
||||
expect(result.message()).toEqual("Expected function to throw an Error, but it threw 4.");
|
||||
});
|
||||
|
||||
function isNotRunningInBrowser() {
|
||||
return typeof document === 'undefined'
|
||||
}
|
||||
|
||||
it("passes if thrown is an instanceof Error regardless of global that contains its constructor", function() {
|
||||
if (isNotRunningInBrowser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
iframe = document.body.appendChild(document.createElement("iframe")),
|
||||
iframeDocument = iframe.contentDocument,
|
||||
result;
|
||||
|
||||
iframeDocument.body.appendChild(iframeDocument.createElement("script"))
|
||||
.textContent = "function method() { throw new Error('foo'); }";
|
||||
|
||||
result = matcher.compare(iframe.contentWindow.method);
|
||||
expect(result.pass).toBe(true);
|
||||
expect(result.message).toEqual("Expected function not to throw an Error, but it threw Error.");
|
||||
|
||||
document.body.removeChild(iframe);
|
||||
});
|
||||
|
||||
it("fails with the correct message if thrown is a falsy value", function() {
|
||||
var matcher = jasmineUnderTest.matchers.toThrowError(),
|
||||
fn = function() {
|
||||
|
||||
@@ -28,7 +28,9 @@ getJasmineRequireObj().toThrowError = function(j$) {
|
||||
return fail;
|
||||
}
|
||||
|
||||
if (!(thrown instanceof Error)) {
|
||||
// Get Error constructor of thrown
|
||||
if (!thrown || !thrown.constructor || !thrown.constructor.constructor ||
|
||||
!(thrown instanceof (thrown.constructor.constructor('return this')()).Error)) {
|
||||
fail.message = function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; };
|
||||
return fail;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user