Skip to content

Commit 3ed1577

Browse files
committed
Adding a negative test case to test a dot in the beginning of the path
1 parent 9f7d35a commit 3ed1577

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,6 +3334,15 @@ Expected value: <g>1</>
33343334
Received value: <r>{"c": {"d": 1}}</>
33353335
`;
33363336

3337+
exports[`.toHaveProperty() {pass: false} expect({"a": {"b": {"c": {}}}}).toHaveProperty('.a.b.c') 1`] = `
3338+
<d>expect(</><r>received</><d>).</>toHaveProperty<d>(</><g>path</><d>)</>
3339+
3340+
Expected path: <g>".a.b.c"</>
3341+
Received path: <r>[]</>
3342+
3343+
Received value: <r>{"a": {"b": {"c": {}}}}</>
3344+
`;
3345+
33373346
exports[`.toHaveProperty() {pass: false} expect({"a": {"b": {"c": {}}}}).toHaveProperty('a.b.c.d') 1`] = `
33383347
<d>expect(</><r>received</><d>).</>toHaveProperty<d>(</><g>path</><d>)</>
33393348

packages/expect/src/__tests__/matchers.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,7 @@ describe('.toHaveProperty()', () => {
19581958

19591959
[
19601960
[{a: {b: {c: {}}}}, 'a.b.c.d'],
1961+
[{a: {b: {c: {}}}}, '.a.b.c'],
19611962
[{a: 1}, 'a.b.c.d'],
19621963
[{}, 'a'],
19631964
[1, 'a.b.c'],

packages/expect/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export const pathAsArray = (propertyPath: string): Array<any> => {
377377
const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
378378
const properties: Array<string> = [];
379379

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

0 commit comments

Comments
 (0)