Back to Medusa

{metadata.title}

www/apps/resources/app/test-tools-reference/normalizeBigNumbers/page.mdx

2.20.12.0 KB
Original Source

import { Table } from "docs-ui"

export const metadata = { title: normalizeBigNumbers Reference, }

{metadata.title}

This is a reference to the normalizeBigNumbers function provided by the @medusajs/test-utils package.

<Note>

This function is available since Medusa v2.19.0.

</Note>

Summary

normalizeBigNumbers recursively converts BigNumber instances to plain JavaScript numbers within any object, array, or primitive value. Dates are left intact.

When you retrieve or create orders and carts in tests, numeric fields such as totals are returned as BigNumber instances rather than plain numbers. Use normalizeBigNumbers when writing Jest assertions against those values so you can compare them to plain-number expectations.

Example

ts
import { medusaIntegrationTestRunner, normalizeBigNumbers } from "@medusajs/test-utils"

medusaIntegrationTestRunner({
  testSuite: ({ api }) => {
    it("returns the correct order totals", async () => {
      const { data: { order } } = await api.get("/admin/orders/order_123")

      expect(normalizeBigNumbers(order)).toMatchObject({
        total: 5000,
        subtotal: 4500,
        tax_total: 500,
      })
    })
  },
})

Parameters

<Table> <Table.Header> <Table.Row> <Table.HeaderCell> Name </Table.HeaderCell> <Table.HeaderCell> Type </Table.HeaderCell> <Table.HeaderCell> Description </Table.HeaderCell> </Table.Row> </Table.Header> <Table.Body> <Table.Row> <Table.Cell> `value` </Table.Cell> <Table.Cell> `any` </Table.Cell> <Table.Cell> The value to normalize. Can be a `BigNumber` instance, a plain object, an array, or any primitive. </Table.Cell> </Table.Row> </Table.Body> </Table>

Returns

Returns the normalized value with all BigNumber instances replaced by plain number values. The original structure (objects, arrays) is preserved. Date instances are returned as-is.