Skip to content

Commit

Permalink
test: add characterization tests for Node13
Browse files Browse the repository at this point in the history
  • Loading branch information
twada committed Apr 18, 2020
1 parent 68cd1fb commit 36a8d18
Showing 1 changed file with 70 additions and 26 deletions.
96 changes: 70 additions & 26 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,29 @@ implementations.forEach(function (impl) {
assert(nothing === undefined);
}, shouldNotBeRejected);
});
it('when actual error is NOT an instanceof `<Class>`, 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 `<Class>`, 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 `<Class>`, 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 {
}
Expand All @@ -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(
Expand All @@ -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');
Expand Down

0 comments on commit 36a8d18

Please sign in to comment.