Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ name: ci
on:
push:
branches:
- v9
- master
pull_request:
workflow_dispatch:

jobs:
test:
uses: hapijs/.github/.github/workflows/ci-module.yml@master
with:
min-node-version: 14
6 changes: 3 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Copyright (c) 2014-2012, Sideway Inc, and project contributors
Copyright (c) 2014, Walmart
Copyright (c) 2011-2014 Jake Luer
Copyright (c) 2014-2022, Sideway Inc, and project contributors
Copyright (c) 2014, Walmart
Copyright (c) 2011-2014 Jake Luer
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
22 changes: 11 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ internals.atUnnamedRx = /^\s*at (?:async )?(.+)\:(\d+)\:(\d+)\)?$/;

exports.thrownAt = function (error) {

error = error || new Error();
error = error ?? new Error();
const stack = typeof error.stack === 'string' ? error.stack : '';
const frame = stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0] || '';
const frame = stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0] ?? '';
const at = frame.match(frame.includes('(') ? internals.atNamedRx : internals.atUnnamedRx);
return Array.isArray(at) ? {
filename: at[1],
Expand Down Expand Up @@ -83,7 +83,7 @@ exports.expect = function (value, prefix) {
internals.Assertion = function (ref, prefix, location, at) {

this._ref = ref;
this._prefix = prefix || '';
this._prefix = prefix ?? '';
this._location = location;
this._at = at;
this._flags = {};
Expand Down Expand Up @@ -135,7 +135,7 @@ internals.Assertion.prototype.assert = function (result, verb, actual, expected)
Error.captureStackTrace(error, this.assert);
error.actual = actual;
error.expected = expected;
error.at = exports.thrownAt(error) || this._at;
error.at = exports.thrownAt(error) ?? this._at;
throw error;
};

Expand Down Expand Up @@ -193,7 +193,7 @@ internals.addMethod = function (names, fn) {
internals.addMethod('error', function (...args /* type, message */) {

const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : Error;
const lastArg = args[1] || args[0];
const lastArg = args[1] ?? args[0];
const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null;
const err = this._ref;

Expand Down Expand Up @@ -296,7 +296,7 @@ internals.addMethod('length', internals.length);

internals.equal = function (value, options) {

options = options || {};
options = options ?? {};
const settings = Hoek.applyToDefaults({ prototype: exports.settings.comparePrototypes, deepFunction: true }, options);

const compare = this._flags.shallow ? (a, b) => a === b
Expand Down Expand Up @@ -397,7 +397,7 @@ internals.throw = function (...args /* type, message */) {
internals.assert(this, !this._flags.not || !args.length, 'Cannot specify arguments when expecting not to throw');

const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : null;
const lastArg = args[1] || args[0];
const lastArg = args[1] ?? args[0];
const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null;

let thrown = false;
Expand All @@ -413,7 +413,7 @@ internals.throw = function (...args /* type, message */) {
}

if (message !== null) {
const error = err.message || '';
const error = err.message ?? '';
this.assert(typeof message === 'string' ? error === message : error.match(message), 'throw an error with specified message', error, message);
}

Expand All @@ -433,7 +433,7 @@ internals.reject = async function (...args/* type, message */) {
internals.assert(this, internals.isPromise(this._ref), 'Can only assert reject on promises');

const type = args.length && typeof args[0] !== 'string' && !(args[0] instanceof RegExp) ? args[0] : null;
const lastArg = args[1] || args[0];
const lastArg = args[1] ?? args[0];
const message = typeof lastArg === 'string' || lastArg instanceof RegExp ? lastArg : null;

let thrown = null;
Expand All @@ -456,7 +456,7 @@ internals.reject = async function (...args/* type, message */) {
}

if (message !== null) {
const error = thrown.message || '';
const error = thrown.message ?? '';
this.assert(typeof message === 'string' ? error === message : error.match(message), 'reject with an error with specified message', error, message);
}

Expand All @@ -479,7 +479,7 @@ internals.addMethod(['reject', 'rejects'], internals.reject);

internals.isPromise = function (promise) {

return promise && typeof promise.then === 'function';
return typeof promise?.then === 'function';
};


Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
},
"devDependencies": {
"@hapi/eslint-plugin": "*",
"@hapi/lab": "24.x.x",
"typescript": "~4.0.2"
"@hapi/lab": "25.0.0-beta.0",
"@types/node": "^17.0.25",
"typescript": "~4.6.3"
},
"scripts": {
"test": "lab -t 100 -L -Y",
Expand Down
6 changes: 3 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ describe('expect()', () => {

it('invalidates assertion (anonymous type)', () => {

const Custom = function () { };
Util.inherits(Custom, Error);
delete Custom.name; // Ensure that the type is anonymous
const Custom = class extends Error {
static name = undefined; // Ensure that the type is anonymous
};

try {
Code.expect(error).to.be.an.error(Custom);
Expand Down