Skip to content

Commit

Permalink
Adding a negative test case to test a dot in the beginning of the path
Browse files Browse the repository at this point in the history
  • Loading branch information
iifawzi committed Nov 28, 2021
1 parent 9f7d35a commit 3ed1577
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Expand Up @@ -3334,6 +3334,15 @@ Expected value: <g>1</>
Received value: <r>{"c": {"d": 1}}</>
`;

exports[`.toHaveProperty() {pass: false} expect({"a": {"b": {"c": {}}}}).toHaveProperty('.a.b.c') 1`] = `
<d>expect(</><r>received</><d>).</>toHaveProperty<d>(</><g>path</><d>)</>

Expected path: <g>".a.b.c"</>
Received path: <r>[]</>

Received value: <r>{"a": {"b": {"c": {}}}}</>
`;

exports[`.toHaveProperty() {pass: false} expect({"a": {"b": {"c": {}}}}).toHaveProperty('a.b.c.d') 1`] = `
<d>expect(</><r>received</><d>).</>toHaveProperty<d>(</><g>path</><d>)</>

Expand Down
1 change: 1 addition & 0 deletions packages/expect/src/__tests__/matchers.test.js
Expand Up @@ -1958,6 +1958,7 @@ describe('.toHaveProperty()', () => {

[
[{a: {b: {c: {}}}}, 'a.b.c.d'],
[{a: {b: {c: {}}}}, '.a.b.c'],
[{a: 1}, 'a.b.c.d'],
[{}, 'a'],
[1, 'a.b.c'],
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/utils.ts
Expand Up @@ -377,7 +377,7 @@ export const pathAsArray = (propertyPath: string): Array<any> => {
const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
const properties: Array<string> = [];

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

0 comments on commit 3ed1577

Please sign in to comment.