Skip to content

Commit

Permalink
Fix types. Skip captureStackTrace when not available. Closes #340. Cl…
Browse files Browse the repository at this point in the history
…oses #341
  • Loading branch information
hueniverse committed Oct 5, 2019
1 parent e6950f2 commit 980cc9c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
2 changes: 1 addition & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<contain.Options, 'once'>): boolean;

export namespace contain {

Expand Down
14 changes: 9 additions & 5 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(Hoek.deepEqual(1, 2));

Expand Down Expand Up @@ -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 });
Expand All @@ -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()

Expand Down Expand Up @@ -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<Promise<void>>(Hoek.wait());
expect.type<void>(await Hoek.wait(100));

expect.error(Hoek.wait({}));
// $lab:types:on$


// block()

// $lab:types:off$
Hoek.wait();

expect.type<Promise<void>>(Hoek.block());
expect.type<void>(await Hoek.block());

expect.error(Hoek.block(123));
// $lab:types:on$

0 comments on commit 980cc9c

Please sign in to comment.