normalizeBigNumbers Reference

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.

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#

Code
1import { medusaIntegrationTestRunner, normalizeBigNumbers } from "@medusajs/test-utils"2
3medusaIntegrationTestRunner({4  testSuite: ({ api }) => {5    it("returns the correct order totals", async () => {6      const { data: { order } } = await api.get("/admin/orders/order_123")7
8      expect(normalizeBigNumbers(order)).toMatchObject({9        total: 50,10        subtotal: 45,11        tax_total: 5,12      })13    })14  },15})

Parameters#

Name

Type

Description

value

any

The value to normalize. Can be a BigNumber instance, a plain object, an array, or any primitive.

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.

Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵