Skip to content

Commit

Permalink
fix(toHaveProperty): add a fix for .toHaveProperty('')
Browse files Browse the repository at this point in the history
  • Loading branch information
chentsulin committed Jan 23, 2022
1 parent 12fee45 commit 9317925
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/expect/src/utils.ts
Expand Up @@ -373,9 +373,15 @@ export const partition = <T>(
};

export const pathAsArray = (propertyPath: string): Array<any> => {
const properties: Array<string> = [];

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<string> = [];

// Because the regex won't match a dot in the beginning of the path, if present.
if (propertyPath[0] === '.') {
Expand Down

0 comments on commit 9317925

Please sign in to comment.