diff --git a/.github/workflows/ci-module.yml b/.github/workflows/ci-module.yml index 18ea44f..54426ca 100644 --- a/.github/workflows/ci-module.yml +++ b/.github/workflows/ci-module.yml @@ -3,7 +3,6 @@ name: ci on: push: branches: - - v9 - master pull_request: workflow_dispatch: diff --git a/API.md b/API.md index cb39273..7f0f1fb 100755 --- a/API.md +++ b/API.md @@ -625,7 +625,7 @@ and compared to the provided optional requirements where: - `message` a string or regular expression matching the rejected error `message` property. Note that a string must provide a full match. -Returns the rejected error object. +Returns a promise resolving to the rejected error object. ```js const NodeUtil = require('util'); diff --git a/LICENSE.md b/LICENSE.md index 82fe1b1..244fd32 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,5 @@ -Copyright (c) 2014-2022, Sideway Inc, and project contributors +Copyright (c) 2014-2022, Project contributors +Copyright (c) 2014-2020, Sideway Inc Copyright (c) 2014, Walmart Copyright (c) 2011-2014 Jake Luer All rights reserved. diff --git a/lib/index.d.ts b/lib/index.d.ts index 4759610..f9de592 100755 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -504,6 +504,16 @@ declare namespace expect { */ above(value: T): Assertion; + /** + * Asserts that the reference value is within a delta difference from the provided value. + * + * @param value - the value to compare to. + * @param delta - the delta +/- range value. + * + * @returns assertion chain object. + */ + about(value: T, delta: number): Assertion; + /** * Asserts that the reference value is greater than (>) the provided value. * @@ -616,10 +626,10 @@ declare namespace expect { * @param type - constructor function the error must be an instance of. * @param message - string or regular expression the error message must match. * - * @returns rejected value. + * @returns a promise resolving to the rejected value. */ - reject(type: Class, message?: string | RegExp): E; - reject(message?: string | RegExp): E; + reject(type: Class, message?: string | RegExp): Promise; + reject(message?: string | RegExp): Promise; /** * Asserts that the Promise reference value rejects with an exception when called. @@ -627,10 +637,10 @@ declare namespace expect { * @param type - constructor function the error must be an instance of. * @param message - string or regular expression the error message must match. * - * @returns rejected value. + * @returns a promise resolving to the rejected value. */ - rejects(type: Class, message?: string | RegExp): E; - rejects(message?: string | RegExp): E; + rejects(type: Class, message?: string | RegExp): Promise; + rejects(message?: string | RegExp): Promise; } interface Not_PromiseAssertion extends BaseAssertion { @@ -638,15 +648,15 @@ declare namespace expect { /** * Asserts that the Promise reference value rejects with an exception when called. * - * @returns null. + * @returns a promise resolving to null. */ - reject(): null; + reject(): Promise; /** * Asserts that the Promise reference value rejects with an exception when called. * - * @returns null. + * @returns a promise resolving to null. */ - rejects(): null; + rejects(): Promise; } } diff --git a/lib/index.js b/lib/index.js index a456866..cd20268 100755 --- a/lib/index.js +++ b/lib/index.js @@ -356,7 +356,7 @@ internals.between = function (from, to) { internals.addMethod('between', internals.between); -internals.above = function (value, delta) { +internals.about = function (value, delta) { internals.assert(this, internals.type(this._ref) === 'number', 'Can only assert about on numbers'); internals.assert(this, internals.type(value) === 'number' && internals.type(delta) === 'number', 'About assertion requires two number arguments'); @@ -364,7 +364,7 @@ internals.above = function (value, delta) { return this.assert(Math.abs(this._ref - value) <= delta, 'be about ' + value + ' \u00b1' + delta); }; -internals.addMethod('about', internals.above); +internals.addMethod('about', internals.about); internals.instanceof = function (type) { diff --git a/package.json b/package.json index 8f9acdf..5ed5047 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hapi/code", "description": "assertion library", - "version": "8.0.7", + "version": "9.0.3", "repository": "git://github.com/hapijs/code", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -19,11 +19,11 @@ ] }, "dependencies": { - "@hapi/hoek": "9.x.x" + "@hapi/hoek": "^11.0.2" }, "devDependencies": { - "@hapi/eslint-plugin": "*", - "@hapi/lab": "25.0.0-beta.0", + "@hapi/eslint-plugin": "^6.0.0", + "@hapi/lab": "^25.0.1", "@types/node": "^17.0.25", "typescript": "~4.6.3" }, diff --git a/test/index.ts b/test/index.ts index d756dd2..12e9476 100755 --- a/test/index.ts +++ b/test/index.ts @@ -186,8 +186,8 @@ Code.expect(type2).to.equal({ a: [1] }, { skip: ['c'] }); const rejection = Promise.reject(new Error('Oh no!')); -await expect.type>(Code.expect(rejection).to.reject('Oh no!')); -await expect.type>(Code.expect(rejection).rejects('Oh no!')); +expect.type>(Code.expect(rejection).to.reject('Oh no!')); +expect.type>(Code.expect(rejection).rejects('Oh no!')); class CustomError extends Error { } @@ -200,10 +200,10 @@ Code.expect(throws).to.throw(CustomError, 'Oh no!'); Code.expect(() => { }).to.not.throw().and.to.be.a.function(); const typedRejection = Promise.reject(new CustomError('Oh no!')); -await expect.type(Code.expect(typedRejection).to.reject(CustomError, 'Oh no!')); -await expect.type(Code.expect(typedRejection).rejects(CustomError, 'Oh no!')); +expect.type>(Code.expect(typedRejection).to.reject(CustomError, 'Oh no!')); +expect.type>(Code.expect(typedRejection).rejects(CustomError, 'Oh no!')); -await expect.type(Code.expect(Promise.resolve(true)).to.not.reject()); +expect.type>(Code.expect(Promise.resolve(true)).to.not.reject()); function foo(): number | undefined { return 123;