Files
medusa-store/packages/medusa-js/test/utils/utils.test.ts
Oliver Windall Juhl 7bee57f7c5 fix(medusa-js): Fix stringifyNullProperties util (#1766)
**What**
Changes the order of object type evaluation to properly handle null properties.

Previously, `stringifyNullProperties({ test: null })` would fail in the 2nd iteration due to an attempt to iterate `null` in `Object.keys(obj)`.
2022-07-02 15:29:27 +00:00

32 lines
889 B
TypeScript

import { stringifyNullProperties } from "../../src/utils"
describe("stringifyNullProperties", () => {
test("returns empty object on no props", () => {
const result = stringifyNullProperties({})
expect(result).toEqual({})
})
test("successfully stringifies null property", () => {
const result = stringifyNullProperties({ test: null })
expect(result).toEqual({ test: "null" })
})
test("successfully stringifies nested null property", () => {
const result = stringifyNullProperties({
test: { test_2: { test_3: null } },
another_test: "test",
})
expect(result).toEqual({
test: { test_2: { test_3: "null" } },
another_test: "test",
})
})
test("successfully stringifies string property", () => {
const result = stringifyNullProperties({
test: "test",
})
expect(result).toEqual({ test: "test" })
})
})