Skip to content

Commit

Permalink
fix: support null values in matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg4554 committed Oct 10, 2021
1 parent d2d28d5 commit 5bee9fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/dsl/matchers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,23 @@ describe("Matcher", () => {
})
})

describe("when given an object with null values", () => {
const object = {
some: "data",
more: null,
an: [null],
someObject: {
withData: true,
withNumber: 1,
andNull: null,
},
}

it("returns just that object", () => {
expect(extractPayload(object)).to.deep.eql(object)
})
})

describe("when given an object with some matchers", () => {
const someMatchers = {
some: somethingLike("data"),
Expand Down
2 changes: 1 addition & 1 deletion src/dsl/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export function extractPayload(value: any): any {
return value.map(extractPayload)
}

if (typeof value === "object") {
if (value !== null && typeof value === "object") {
return Object.keys(value).reduce(
(acc: object, propName: string) => ({
...acc,
Expand Down

0 comments on commit 5bee9fc

Please sign in to comment.