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 toHaveLength()

Karel De Smetf53ac25d9062
diff --git a/helpers/__tests__/postwomanTesting.spec.js b/helpers/__tests__/postwomanTesting.spec.js
index 9746610c0..fbd77e7cb 100644
--- a/helpers/__tests__/postwomanTesting.spec.js
+++ b/helpers/__tests__/postwomanTesting.spec.js
@@ -150,3 +150,19 @@ describe("toBeLevel5xx()", () => {
}).toThrow()
})
})
+
+describe("toHaveLength()", () => {
+ test("test for strings", () => {
+ expect(getTestResult("pw.expect('word').toHaveLength(4)", 0)).toEqual(PASS)
+ expect(getTestResult("pw.expect('word').toHaveLength(5)", 0)).toEqual(FAIL)
+ expect(getTestResult("pw.expect('word').not.toHaveLength(4)", 0)).toEqual(FAIL)
+ expect(getTestResult("pw.expect('word').not.toHaveLength(5)", 0)).toEqual(PASS)
+ })
+ test("test for arrays", () => {
+ const fruits = "['apples', 'bananas', 'oranges', 'grapes', 'strawberries', 'cherries']"
+ expect(getTestResult(`pw.expect(${fruits}).toHaveLength(6)`, 0)).toEqual(PASS)
+ expect(getTestResult(`pw.expect(${fruits}).toHaveLength(7)`, 0)).toEqual(FAIL)
+ expect(getTestResult(`pw.expect(${fruits}).not.toHaveLength(6)`, 0)).toEqual(FAIL)
+ expect(getTestResult(`pw.expect(${fruits}).not.toHaveLength(7)`, 0)).toEqual(PASS)
+ })
+})