-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Convert es2018/throws.js to main, fix Chrome-specific expect
* Improve "failing assertions" to check the failure. This is based on the "inspect expected values" variant, but now applied to both cases. * Improve "does not die" test to not hardcode the exact message that Chrome throws. Make it pass in Firefox and Safari too, which use slightly different error messages.
- Loading branch information
Showing
11 changed files
with
145 additions
and
90 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
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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>QUnit Main Test Suite</title> | ||
<link rel="stylesheet" href="../src/qunit.css"> | ||
<script src="../qunit/qunit.js"></script> | ||
<script> | ||
// For main/module.js | ||
QUnit.config.reorder = false; | ||
</script> | ||
|
||
<script src="main/assert.js"></script> | ||
<script src="main/assert-step.js"></script> | ||
<script src="main/assert-timeout.js"></script> | ||
<script src="main/async.js"></script> | ||
<script src="main/deepEqual.js"></script> | ||
<script src="main/diff.js"></script> | ||
<script src="main/dump.js"></script> | ||
<script src="main/each.js"></script> | ||
<script src="main/HtmlReporter.js"></script> | ||
<script src="main/modules.js"></script> | ||
<script src="main/onUncaughtException.js"></script> | ||
<script src="main/promise.js"></script> | ||
<script src="main/setTimeout.js"></script> | ||
<script src="main/stacktrace.js"></script> | ||
<script src="main/test.js"></script> | ||
<script src="main/utilities.js"></script> | ||
|
||
<script src="reporter-html/unhandled-rejection.js"></script> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
<div id="qunit-fixture">test markup</div> | ||
</body> | ||
</html> |
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,88 @@ | ||
QUnit.module('assert.throws [es6]', function () { | ||
function CustomError (message) { | ||
this.message = message; | ||
} | ||
|
||
CustomError.prototype.toString = function () { | ||
return this.message; | ||
}; | ||
|
||
QUnit.test('throws [matcher arrow function]', function (assert) { | ||
assert.throws( | ||
function () { | ||
throw new CustomError('some error description'); | ||
}, | ||
err => { | ||
return err instanceof CustomError && /description/.test(err); | ||
} | ||
); | ||
}); | ||
|
||
QUnit.test('throws [matcher Error subclass]', function (assert) { | ||
class CustomError extends Error {} | ||
|
||
assert.throws( | ||
function () { | ||
throw new CustomError('foo'); | ||
}, | ||
CustomError | ||
); | ||
}); | ||
|
||
// TODO: Once we run browser tests with QTap, remove this hack | ||
// and instead write expected failures in .tap.txt snapshots. | ||
QUnit.module('failing assertions', function (hooks) { | ||
hooks.beforeEach(function (assert) { | ||
const original = assert.pushResult; | ||
assert.pushResult = (resultInfo) => { | ||
if (this.expectedFailure && | ||
this.expectedFailure.actual === resultInfo.actual && | ||
this.expectedFailure.expected.test(resultInfo.expected) | ||
) { | ||
// Restore | ||
assert.pushResult = original; | ||
this.expectedFailure = null; | ||
// Inverts the result of the (one) expected failure | ||
resultInfo.result = !resultInfo.result; | ||
} | ||
|
||
return original.call(this, resultInfo); | ||
}; | ||
}); | ||
|
||
QUnit.test('throws [matcher arrow fn returns false]', function (assert) { | ||
this.expectedFailure = { | ||
actual: 'Error: foo', | ||
expected: /^null$/ | ||
}; | ||
|
||
assert.throws( | ||
function () { | ||
throw new Error('foo'); | ||
}, | ||
() => false | ||
); | ||
}); | ||
|
||
QUnit.test('throws [graceful failure when class given as matcher]', function (assert) { | ||
// Avoid uncaught "Died on test" and instead report it | ||
// gracefully as an assertion failure | ||
// https://github.com/qunitjs/qunit/issues/1530 | ||
this.expectedFailure = { | ||
actual: 'Error: foo', | ||
// [Firefox 127] TypeError: class constructors must be invoked with 'new' | ||
// [Safari 17] TypeError: Cannot call a class constructor without |new| | ||
// [Chrome 126] TypeError: Class constructor CustomError cannot be invoked without 'new' | ||
expected: /^TypeError: .*[Cc]lass constructors? .*\bnew/ | ||
}; | ||
|
||
class CustomError extends Error {} | ||
assert.throws( | ||
() => { | ||
throw new Error('foo'); | ||
}, | ||
CustomError | ||
); | ||
}); | ||
}); | ||
}); |
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