Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

Test for toBeLevel4xx()

Karel De Smeta61e6efdd468
diff --git a/helpers/__tests__/postwomanTesting.spec.js b/helpers/__tests__/postwomanTesting.spec.js
index 5340e4aa7..3b6e19551 100644
--- a/helpers/__tests__/postwomanTesting.spec.js
+++ b/helpers/__tests__/postwomanTesting.spec.js
@@ -106,3 +106,25 @@ describe("toBeLevel3xx()", () => {
}).toThrow()
})
})
+
+describe("toBeLevel4xx()", () => {
+ test("test for numbers", () => {
+ expect(getTestResult("pw.expect(400).toBeLevel4xx()", 0)).toEqual(PASS)
+ expect(getTestResult("pw.expect(400).not.toBeLevel4xx()", 0)).toEqual(FAIL)
+ expect(getTestResult("pw.expect(500).toBeLevel4xx()", 0)).toEqual(FAIL)
+ expect(getTestResult("pw.expect(500).not.toBeLevel4xx()", 0)).toEqual(PASS)
+ })
+ test("test for strings", () => {
+ expect(getTestResult("pw.expect('400').toBeLevel4xx()", 0)).toEqual(PASS)
+ expect(getTestResult("pw.expect('400').not.toBeLevel4xx()", 0)).toEqual(FAIL)
+ expect(getTestResult("pw.expect('500').toBeLevel4xx()", 0)).toEqual(FAIL)
+ expect(getTestResult("pw.expect('500').not.toBeLevel4xx()", 0)).toEqual(PASS)
+ })
+ test("failed to parse to integer", () => {
+ expect(getTestResult("pw.expect(undefined).toBeLevel4xx()", 0)).toEqual(FAIL)
+ expect(getTestResult("pw.expect(null).toBeLevel4xx()", 0)).toEqual(FAIL)
+ expect(() => {
+ runTestScriptWithVariables("pw.expect(Symbol('test')).toBeLevel4xx()")
+ }).toThrow()
+ })
+})