|
1
|
import { Table } from "docs-ui" |
|
2
|
|
|
3
|
export const metadata = { |
|
4
|
title: `normalizeBigNumbers Reference`, |
|
5
|
} |
|
6
|
|
|
7
|
# {metadata.title} |
|
8
|
|
|
9
|
This is a reference to the `normalizeBigNumbers` function provided by the `@medusajs/test-utils` package. |
|
10
|
|
|
11
|
<Note> |
|
12
|
|
|
13
|
This function is available since Medusa [v2.19.0](https://github.com/medusajs/medusa/releases/tag/v2.19.0). |
|
14
|
|
|
15
|
</Note> |
|
16
|
|
|
17
|
## Summary |
|
18
|
|
|
19
|
`normalizeBigNumbers` recursively converts `BigNumber` instances to plain JavaScript numbers within any object, array, or primitive value. Dates are left intact. |
|
20
|
|
|
21
|
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. |
|
22
|
|
|
23
|
## Example |
|
24
|
|
|
25
|
```ts |
|
26
|
import { medusaIntegrationTestRunner, normalizeBigNumbers } from "@medusajs/test-utils" |
|
27
|
|
|
28
|
medusaIntegrationTestRunner({ |
|
29
|
testSuite: ({ api }) => { |
|
30
|
it("returns the correct order totals", async () => { |
|
31
|
const { data: { order } } = await api.get("/admin/orders/order_123") |
|
32
|
|
|
33
|
expect(normalizeBigNumbers(order)).toMatchObject({ |
|
34
|
total: 50, |
|
35
|
subtotal: 45, |
|
36
|
tax_total: 5, |
|
37
|
}) |
|
38
|
}) |
|
39
|
}, |
|
40
|
}) |
|
41
|
``` |
|
42
|
|
|
43
|
## Parameters |
|
44
|
|
|
45
|
<Table> |
|
46
|
<Table.Header> |
|
47
|
<Table.Row> |
|
48
|
<Table.HeaderCell> |
|
49
|
Name |
|
50
|
</Table.HeaderCell> |
|
51
|
<Table.HeaderCell> |
|
52
|
Type |
|
53
|
</Table.HeaderCell> |
|
54
|
<Table.HeaderCell> |
|
55
|
Description |
|
56
|
</Table.HeaderCell> |
|
57
|
</Table.Row> |
|
58
|
</Table.Header> |
|
59
|
<Table.Body> |
|
60
|
<Table.Row> |
|
61
|
<Table.Cell> |
|
62
|
`value` |
|
63
|
</Table.Cell> |
|
64
|
<Table.Cell> |
|
65
|
`any` |
|
66
|
</Table.Cell> |
|
67
|
<Table.Cell> |
|
68
|
The value to normalize. Can be a `BigNumber` instance, a plain object, an array, or any primitive. |
|
69
|
</Table.Cell> |
|
70
|
</Table.Row> |
|
71
|
</Table.Body> |
|
72
|
</Table> |
|
73
|
|
|
74
|
## Returns |
|
75
|
|
|
76
|
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. |