From 9317925f1afa556a00990930025a0ca9cc069c0f Mon Sep 17 00:00:00 2001 From: chentsulin Date: Sun, 23 Jan 2022 14:15:58 +0800 Subject: [PATCH] fix(toHaveProperty): add a fix for .toHaveProperty('') --- packages/expect/src/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/expect/src/utils.ts b/packages/expect/src/utils.ts index 725289ebb3a4..9e546c303c26 100644 --- a/packages/expect/src/utils.ts +++ b/packages/expect/src/utils.ts @@ -373,9 +373,15 @@ export const partition = ( }; export const pathAsArray = (propertyPath: string): Array => { + const properties: Array = []; + + if (propertyPath === '') { + properties.push(''); + return properties; + } + // will match everything that's not a dot or a bracket, and "" for consecutive dots. const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g'); - const properties: Array = []; // Because the regex won't match a dot in the beginning of the path, if present. if (propertyPath[0] === '.') {