diff --git a/test/test.js b/test/test.js index 1095aa2..160c6e8 100644 --- a/test/test.js +++ b/test/test.js @@ -179,15 +179,29 @@ implementations.forEach(function (impl) { assert(nothing === undefined); }, shouldNotBeRejected); }); - it('when actual error is NOT an instanceof ``, rejects with the actual error.', function () { - return rejects( - willReject(new TypeError('the original error message')), - RangeError - ).then(shouldNotBeFulfilled, function (err) { - assert(err instanceof TypeError); - assert.equal(err.message, 'the original error message'); + // Node 13 + if (impl.name === 'official implementation' && semver.satisfies(process.version, '>= 13.0.0')) { + it('when actual error is NOT an instanceof ``, rejects with AssertionError.', function () { + return rejects( + willReject(new TypeError('the original error message')), + RangeError + ).then(shouldNotBeFulfilled, function (err) { + assert(err instanceof assert.AssertionError); + assert(/The error is expected to be an instance of "RangeError". Received "TypeError"/.test(err.message)); + assert(/the original error message/.test(err.message)); + }); }); - }); + } else { + it('when actual error is NOT an instanceof ``, rejects with the actual error.', function () { + return rejects( + willReject(new TypeError('the original error message')), + RangeError + ).then(shouldNotBeFulfilled, function (err) { + assert(err instanceof TypeError); + assert.equal(err.message, 'the original error message'); + }); + }); + } describe('works well with ES2015 classes that extends Error', function () { class ES2015Error extends Error { } @@ -201,15 +215,29 @@ implementations.forEach(function (impl) { assert(nothing === undefined); }, shouldNotBeRejected); }); - it('unmatch case, rejects with the original error.', function () { - return rejects( - willReject(new AnotherES2015Error('bar')), - ES2015Error - ).then(shouldNotBeFulfilled, function (err) { - assert(err instanceof AnotherES2015Error); - assert.equal(err.message, 'bar'); + // Node 13 + if (impl.name === 'official implementation' && semver.satisfies(process.version, '>= 13.0.0')) { + it('unmatch case, rejects with AssertionError.', function () { + return rejects( + willReject(new AnotherES2015Error('bar')), + ES2015Error + ).then(shouldNotBeFulfilled, function (err) { + assert(err instanceof assert.AssertionError); + assert(/The error is expected to be an instance of "ES2015Error". Received "AnotherES2015Error"/.test(err.message)); + assert(/bar/.test(err.message)); + }); }); - }); + } else { + it('unmatch case, rejects with the original error.', function () { + return rejects( + willReject(new AnotherES2015Error('bar')), + ES2015Error + ).then(shouldNotBeFulfilled, function (err) { + assert(err instanceof AnotherES2015Error); + assert.equal(err.message, 'bar'); + }); + }); + } }); it('appends `error.name` as expected error class name to the message if the `promiseFn` is not rejected.', function () { return rejects( @@ -232,17 +260,33 @@ implementations.forEach(function (impl) { assert(nothing === undefined); }, shouldNotBeRejected); }); - it('when returned value of validation function is NOT `true`, rejects with the actual error.', function () { - return rejects( - willReject(new RangeError('Wrong range')), - function (err) { - return ((err instanceof TypeError) && /type/.test(err)); - } - ).then(shouldNotBeFulfilled, function (err) { - assert(err instanceof RangeError); - assert.equal(err.message, 'Wrong range'); + // Node 13 + if (impl.name === 'official implementation' && semver.satisfies(process.version, '>= 13.0.0')) { + it('when returned value of validation function is NOT `true`, rejects with AssertionError.', function () { + return rejects( + willReject(new RangeError('Wrong range')), + function (err) { + return ((err instanceof TypeError) && /type/.test(err)); + } + ).then(shouldNotBeFulfilled, function (err) { + assert(err instanceof assert.AssertionError); + assert(/The validation function is expected to return "true". Received false/.test(err.message)); + assert(/RangeError: Wrong range/.test(err.message)); + }); }); - }); + } else { + it('when returned value of validation function is NOT `true`, rejects with the actual error.', function () { + return rejects( + willReject(new RangeError('Wrong range')), + function (err) { + return ((err instanceof TypeError) && /type/.test(err)); + } + ).then(shouldNotBeFulfilled, function (err) { + assert(err instanceof RangeError); + assert.equal(err.message, 'Wrong range'); + }); + }); + } it('if Error is thrown from validation function, rejects with the error.', function () { var e = new RangeError('the original error message'); var te = new TypeError('some programming error');