From d92412175c03a5054dfaa4aa18adabc965ca83a1 Mon Sep 17 00:00:00 2001 From: Karel De Smet Date: Tue, 22 Dec 2020 08:01:55 +0100 Subject: [PATCH] Test for toBeLevel3xx() --- helpers/__tests__/postwomanTesting.spec.js | 22 ++++++++++++++++++++++ helpers/postwomanTesting.js | 8 ++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/helpers/__tests__/postwomanTesting.spec.js b/helpers/__tests__/postwomanTesting.spec.js index 1bf16a060..5340e4aa7 100644 --- a/helpers/__tests__/postwomanTesting.spec.js +++ b/helpers/__tests__/postwomanTesting.spec.js @@ -84,3 +84,25 @@ describe("toBeLevel2xx", () => { }).toThrow() }) }) + +describe("toBeLevel3xx()", () => { + test("test for numbers", () => { + expect(getTestResult("pw.expect(300).toBeLevel3xx()", 0)).toEqual(PASS) + expect(getTestResult("pw.expect(300).not.toBeLevel3xx()", 0)).toEqual(FAIL) + expect(getTestResult("pw.expect(400).toBeLevel3xx()", 0)).toEqual(FAIL) + expect(getTestResult("pw.expect(400).not.toBeLevel3xx()", 0)).toEqual(PASS) + }) + test("test for strings", () => { + expect(getTestResult("pw.expect('300').toBeLevel3xx()", 0)).toEqual(PASS) + expect(getTestResult("pw.expect('300').not.toBeLevel3xx()", 0)).toEqual(FAIL) + expect(getTestResult("pw.expect('400').toBeLevel3xx()", 0)).toEqual(FAIL) + expect(getTestResult("pw.expect('400').not.toBeLevel3xx()", 0)).toEqual(PASS) + }) + test("failed to parse to integer", () => { + expect(getTestResult("pw.expect(undefined).toBeLevel3xx()", 0)).toEqual(FAIL) + expect(getTestResult("pw.expect(null).toBeLevel3xx()", 0)).toEqual(FAIL) + expect(() => { + runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel3xx()") + }).toThrow() + }) +}) diff --git a/helpers/postwomanTesting.js b/helpers/postwomanTesting.js index 30d0bb8d4..1de644e94 100644 --- a/helpers/postwomanTesting.js +++ b/helpers/postwomanTesting.js @@ -113,7 +113,7 @@ class Expectation { if (Number.isNaN(code)) { return this._fail(`Expected 200-level status but could not parse value ${this.expectValue}`) } - return this._satisfies(code >= 200 && code < 300) + return this._satisfies(code >= 200 && code < 300, true) ? this._pass() : this._fail(this._fmtNot(`Expected ${this.expectValue} to (not)be 200-level status`)) } @@ -122,7 +122,7 @@ class Expectation { if (Number.isNaN(code)) { return this._fail(`Expected 300-level status but could not parse value ${this.expectValue}`) } - return this._satisfies(code >= 300 && code < 400) + return this._satisfies(code >= 300 && code < 400, true) ? this._pass() : this._fail(this._fmtNot(`Expected ${this.expectValue} to (not)be 300-level status`)) } @@ -131,7 +131,7 @@ class Expectation { if (Number.isNaN(code)) { return this._fail(`Expected 400-level status but could not parse value ${this.expectValue}`) } - return this._satisfies(code >= 400 && code < 500) + return this._satisfies(code >= 400 && code < 500, true) ? this._pass() : this._fail(this._fmtNot(`Expected ${this.expectValue} to (not)be 400-level status`)) } @@ -140,7 +140,7 @@ class Expectation { if (Number.isNaN(code)) { return this._fail(`Expected 500-level status but could not parse value ${this.expectValue}`) } - return this._satisfies(code >= 500 && code < 600) + return this._satisfies(code >= 500 && code < 600, true) ? this._pass() : this._fail(this._fmtNot(`Expected ${this.expectValue} to (not)be 500-level status`)) }