From 980cc9cd2de6fb86c6d91a8fe9fc96af5d6d774a Mon Sep 17 00:00:00 2001 From: Eran Hammer Date: Fri, 4 Oct 2019 20:18:13 -0700 Subject: [PATCH] Fix types. Skip captureStackTrace when not available. Closes #340. Closes #341 --- lib/error.js | 5 ++++- lib/index.d.ts | 2 +- test/index.ts | 14 +++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/error.js b/lib/error.js index 056d6f01..9fc4f5df 100755 --- a/lib/error.js +++ b/lib/error.js @@ -18,6 +18,9 @@ module.exports = class extends Error { }); super(msgs.join(' ') || 'Unknown error'); - Error.captureStackTrace(this, exports.assert); + + if (typeof Error.captureStackTrace === 'function') { // $lab:coverage:ignore$ + Error.captureStackTrace(this, exports.assert); + } } }; diff --git a/lib/index.d.ts b/lib/index.d.ts index 4a099464..3eefa496 100755 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -197,7 +197,7 @@ export namespace intersect { */ export function contain(ref: string, values: string | string[], options?: contain.Options): boolean; export function contain(ref: any[], values: any, options?: contain.Options): boolean; -export function contain(ref: object, values: string | string[] | object, options?: contain.Options): boolean; +export function contain(ref: object, values: string | string[] | object, options?: Omit): boolean; export namespace contain { diff --git a/test/index.ts b/test/index.ts index a99e935f..adb37048 100755 --- a/test/index.ts +++ b/test/index.ts @@ -22,7 +22,7 @@ Hoek.deepEqual('some', 'some'); Hoek.deepEqual('some', 3); Hoek.deepEqual({}, {}); Hoek.deepEqual({}, {}, { prototype: false, symbols: true, part: false, deepFunction: true }); -Hoek.deepEqual({}, {}, { skip: ['a', 'b', Symbol('test')]}); +Hoek.deepEqual({}, {}, { skip: ['a', 'b', Symbol('test')] }); expect.type(Hoek.deepEqual(1, 2)); @@ -121,7 +121,7 @@ Hoek.contain('abc', ['a', 'x']); Hoek.contain('abc', ['a', 'd'], { once: true, part: true, deep: true, symbols: true, only: true }); Hoek.contain({ a: 1 }, 'a'); Hoek.contain({ a: 1 }, { a: 1 }); -Hoek.contain({ a: 1, b: 2 }, ['a', 'x'], { once: true, part: true, deep: true, symbols: true, only: true }); +Hoek.contain({ a: 1, b: 2 }, ['a', 'x'], { part: true, deep: true, symbols: true, only: true }); Hoek.contain([1], 1); Hoek.contain([1], [1]); Hoek.contain([1], [1], { once: true, part: true, deep: true, symbols: true, only: true }); @@ -138,7 +138,7 @@ expect.error(Hoek.contain('abc', [1])); expect.error(Hoek.contain('abc', [{}])); expect.error(Hoek.contain('abc', {})); expect.error(Hoek.contain({}, 1)); - +expect.error(Hoek.contain({ a: 1, b: 2 }, ['a', 'x'], { once: true })); // flatten() @@ -299,20 +299,24 @@ expect.error(Hoek.stringify()); // wait() -Hoek.wait(); -Hoek.wait(123); +// $lab:types:off$ +await Hoek.wait(); +await Hoek.wait(123); expect.type>(Hoek.wait()); expect.type(await Hoek.wait(100)); expect.error(Hoek.wait({})); +// $lab:types:on$ // block() +// $lab:types:off$ Hoek.wait(); expect.type>(Hoek.block()); expect.type(await Hoek.block()); expect.error(Hoek.block(123)); +// $lab:types:on$