From f53ac25d906211d5e793beae63a39e10f0f48e8a Mon Sep 17 00:00:00 2001 From: Karel De Smet Date: Tue, 22 Dec 2020 20:05:56 +0100 Subject: [PATCH] Test for toHaveLength() --- helpers/__tests__/postwomanTesting.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/helpers/__tests__/postwomanTesting.spec.js b/helpers/__tests__/postwomanTesting.spec.js index 9746610c..fbd77e7c 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) + }) +})