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 f99fc67 commit 345b908
Showing 1 changed file with 39 additions and 30 deletions.
69 changes: 39 additions & 30 deletions test/test.js
Expand Up @@ -179,26 +179,29 @@ implementations.forEach(function (impl) {
assert(nothing === undefined);
}, shouldNotBeRejected);
});
// 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 () {
// < Node13
if (impl.name === 'official implementation' && semver.satisfies(process.version, '< 13.0.0')) {
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 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));
assert(err instanceof TypeError);
assert.equal(err.message, 'the original error message');
});
});
} else {
it('when actual error is NOT an instanceof `<Class>`, rejects with the actual error.', function () {
it('when actual error is NOT an instanceof `<Class>`, rejects with AssertionError.', function () {
var te = new TypeError('the original error message');
return rejects(
willReject(new TypeError('the original error message')),
willReject(te),
RangeError
).then(shouldNotBeFulfilled, function (err) {
assert(err instanceof TypeError);
assert.equal(err.message, 'the original error message');
assert(err instanceof assert.AssertionError);
assert.equal(err.actual, te);
assert.equal(err.expected, RangeError);
assert(/The error is expected to be an instance of "RangeError". Received "TypeError"/.test(err.message));
assert(/the original error message/.test(err.message));
});
});
}
Expand All @@ -215,26 +218,29 @@ implementations.forEach(function (impl) {
assert(nothing === undefined);
}, shouldNotBeRejected);
});
// Node 13
if (impl.name === 'official implementation' && semver.satisfies(process.version, '>= 13.0.0')) {
it('unmatch case, rejects with AssertionError.', function () {
// < Node13
if (impl.name === 'official implementation' && semver.satisfies(process.version, '< 13.0.0')) {
it('unmatch case, rejects with the original error.', 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));
assert(err instanceof AnotherES2015Error);
assert.equal(err.message, 'bar');
});
});
} else {
it('unmatch case, rejects with the original error.', function () {
it('unmatch case, rejects with AssertionError.', function () {
var another = new AnotherES2015Error('bar');
return rejects(
willReject(new AnotherES2015Error('bar')),
willReject(another),
ES2015Error
).then(shouldNotBeFulfilled, function (err) {
assert(err instanceof AnotherES2015Error);
assert.equal(err.message, 'bar');
assert(err instanceof assert.AssertionError);
assert.equal(err.actual, another);
assert.equal(err.expected, ES2015Error);
assert(/The error is expected to be an instance of "ES2015Error". Received "AnotherES2015Error"/.test(err.message));
assert(/bar/.test(err.message));
});
});
}
Expand All @@ -260,30 +266,33 @@ implementations.forEach(function (impl) {
assert(nothing === undefined);
}, shouldNotBeRejected);
});
// 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 () {
// < Node13
if (impl.name === 'official implementation' && semver.satisfies(process.version, '< 13.0.0')) {
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 assert.AssertionError);
assert(/The validation function is expected to return "true". Received false/.test(err.message));
assert(/RangeError: Wrong range/.test(err.message));
assert(err instanceof RangeError);
assert.equal(err.message, 'Wrong range');
});
});
} else {
it('when returned value of validation function is NOT `true`, rejects with the actual error.', function () {
it('when returned value of validation function is NOT `true`, rejects with AssertionError.', function () {
var e = new RangeError('Wrong range');
return rejects(
willReject(new RangeError('Wrong range')),
willReject(e),
function (err) {
return ((err instanceof TypeError) && /type/.test(err));
}
).then(shouldNotBeFulfilled, function (err) {
assert(err instanceof RangeError);
assert.equal(err.message, 'Wrong range');
assert(err instanceof assert.AssertionError);
assert.equal(err.actual, e);
// assert.equal(err.expected, handler);
assert(/The validation function is expected to return "true". Received false/.test(err.message));
assert(/RangeError: Wrong range/.test(err.message));
});
});
}
Expand Down

0 comments on commit 345b908

Please sign in to comment.