diff --git a/package-lock.json b/package-lock.json index 6dd1aaf..d986bd0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pactum", - "version": "3.7.1", + "version": "3.7.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "pactum", - "version": "3.7.1", + "version": "3.7.2", "license": "MIT", "dependencies": { "@exodus/schemasafe": "^1.3.0", diff --git a/package.json b/package.json index cae3648..301ec59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pactum", - "version": "3.7.1", + "version": "3.7.2", "description": "REST API Testing Tool for all levels in a Test Pyramid", "main": "./src/index.js", "types": "./src/index.d.ts", diff --git a/src/models/Spec.d.ts b/src/models/Spec.d.ts index 4d8f577..ff01c43 100644 --- a/src/models/Spec.d.ts +++ b/src/models/Spec.d.ts @@ -416,6 +416,7 @@ declare class Spec { * @see https://pactumjs.github.io/api/requests/inspect.html */ inspect(): Spec; + inspect(enable: boolean): Spec; inspect(path: string): Spec; /** @@ -457,7 +458,7 @@ declare class Spec { */ end(): Spec; - /** + /** * sleep after spec execution * @see https://pactumjs.github.io/api/utils/sleep.html */ diff --git a/src/models/Spec.js b/src/models/Spec.js index 03a0d80..094fa32 100644 --- a/src/models/Spec.js +++ b/src/models/Spec.js @@ -329,7 +329,7 @@ class Spec { return this; } this._request.followRedirects = follow; - return this; + return this; } withCompression() { @@ -516,17 +516,15 @@ class Spec { } inspect(inspect_path) { - if (this._inspect) { - if (typeof this._inspect === 'boolean') { + if (typeof inspect_path === 'string') { + if (!Array.isArray(this._inspect)) { this._inspect = []; } this._inspect.push(inspect_path); + } else if (typeof inspect_path === 'boolean') { + this._inspect = inspect_path; } else { - if (inspect_path) { - this._inspect = [inspect_path]; - } else { - this._inspect = true; - } + this._inspect = true; } return this; } diff --git a/src/models/Tosser.js b/src/models/Tosser.js index 5882273..a25f832 100644 --- a/src/models/Tosser.js +++ b/src/models/Tosser.js @@ -122,7 +122,7 @@ class Tosser { if (this.spec._inspect) { log.warn('Inspecting Request & Response'); if (typeof this.spec._inspect === 'boolean') { - utils.printReqAndRes(this.request, this.response); + this.printRequestAndResponse(); } else { for (let i = 0; i < this.spec._inspect.length; i++) { const inspect_path = this.spec._inspect[i]; @@ -214,7 +214,7 @@ class Tosser { this.spec.status = 'FAILED'; this.spec.failure = error.toString(); this.runReport(); - utils.printReqAndRes(this.request, this.response); + this.printRequestAndResponse(); throw error; } } @@ -224,7 +224,7 @@ class Tosser { this.spec.status = 'ERROR'; this.spec.failure = this.response.toString(); this.runReport(); - utils.printReqAndRes(this.request, this.response); + this.printRequestAndResponse(); this.expect.fail(this.response); } } @@ -249,6 +249,12 @@ class Tosser { } } + printRequestAndResponse() { + if (this.spec._inspect !== false) { + utils.printReqAndRes(this.request, this.response); + } + } + } async function getResponse(tosser) { diff --git a/test/component/inspect.spec.js b/test/component/inspect.spec.js index 240a05e..5bd16da 100644 --- a/test/component/inspect.spec.js +++ b/test/component/inspect.spec.js @@ -36,4 +36,16 @@ describe('Inspect', () => { .inspect('people[country=AU]'); }); + it('do not inspect on failure', async () => { + try { + await spec() + .useInteraction('get people') + .get('http://localhost:9393/api/people') + .expectStatus(400) + .inspect(false); + } catch { + + } + }); + }); \ No newline at end of file