Skip to content

Commit

Permalink
Test: Convert es2018/rejects.js to main/assert-es6.js
Browse files Browse the repository at this point in the history
Follows-up bf1406e.
  • Loading branch information
Krinkle committed Jul 8, 2024
1 parent c40934f commit 218adec
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 84 deletions.
5 changes: 2 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ module.exports = function (grunt) {

// Sync with test/index.html
'test/main/assert.js',
'test/main/assert-es6.js',
'test/main/assert-step.js',
'test/main/assert-throws-es6.js',
'test/main/assert-timeout.js',
'test/main/async.js',
'test/main/deepEqual.js',
Expand All @@ -143,8 +143,7 @@ module.exports = function (grunt) {
'test/node/storage-1.js',
'test/node/storage-2.js',

'test/es2018/async-functions.js',
'test/es2018/rejects.js'
'test/es2018/async-functions.js'
]
}
});
Expand Down
77 changes: 0 additions & 77 deletions test/es2018/rejects.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</script>

<script src="main/assert.js"></script>
<script src="main/assert-es6.js"></script>
<script src="main/assert-step.js"></script>
<script src="main/assert-throws-es6.js"></script>
<script src="main/assert-timeout.js"></script>
<script src="main/async.js"></script>
<script src="main/deepEqual.js"></script>
Expand Down
45 changes: 44 additions & 1 deletion test/main/assert-throws-es6.js → test/main/assert-es6.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QUnit.module('assert.throws [es6]', function () {
QUnit.module('assert [es6]', function () {
function CustomError (message) {
this.message = message;
}
Expand All @@ -18,6 +18,15 @@ QUnit.module('assert.throws [es6]', function () {
);
});

QUnit.test('rejects [matcher arrow function]', function (assert) {
assert.rejects(
Promise.reject(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 {}

Expand All @@ -29,6 +38,15 @@ QUnit.module('assert.throws [es6]', function () {
);
});

QUnit.test('rejects [matcher Error subclass]', function (assert) {
class CustomError extends Error {}

assert.rejects(
Promise.reject(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) {
Expand Down Expand Up @@ -64,6 +82,18 @@ QUnit.module('assert.throws [es6]', function () {
);
});

QUnit.test('rejects [matcher arrow fn returns false]', function (assert) {
this.expectedFailure = {
actual: 'Error: foo',
expected: /^null$/
};

assert.rejects(
Promise.reject(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
Expand All @@ -84,5 +114,18 @@ QUnit.module('assert.throws [es6]', function () {
CustomError
);
});

QUnit.test('rejects [graceful failure when class given as matcher]', function (assert) {
this.expectedFailure = {
actual: 'Error: foo',
expected: /^TypeError: .*[Cc]lass constructors? .*\bnew/
};

class CustomError extends Error {}
assert.rejects(
Promise.reject(new Error('foo')),
CustomError
);
});
});
});
2 changes: 1 addition & 1 deletion test/mozjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ QUnit.on('runEnd', (suiteEnd) => {

// Sync with test/index.html
loadRelativeToScript('../test/main/assert.js');
loadRelativeToScript('../test/main/assert-es6.js');
loadRelativeToScript('../test/main/assert-step.js');
loadRelativeToScript('../test/main/assert-throws-es6.js');
// loadRelativeToScript( "../test/main/assert-timeout.js" ); // Requires setTimeout
// loadRelativeToScript( "../test/main/async.js" ); // Requires setTimeout
loadRelativeToScript('../test/main/deepEqual.js');
Expand Down
2 changes: 1 addition & 1 deletion test/webWorker-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ importScripts(

// Sync with test/index.html
'main/assert.js',
'main/assert-es6.js',
'main/assert-step.js',
'main/assert-throws-es6.js',
'main/assert-timeout.js',
'main/async.js',
'main/deepEqual.js',
Expand Down

0 comments on commit 218adec

Please sign in to comment.