d3/d3-array

Testing a lib using `d3-array`

tk-o opened this issue · 1 comments

tk-o commented

Context

When I run jest tests, I receive the following error:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export {default as bisect, bisectRight, bisectLeft, bisectCenter} from "./bisect.js";
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

      1 | import { useCallback, useEffect } from "react";
      2 |
    > 3 | import { extent, max } from "d3-array";
        | ^
      4 | import { scaleTime, scaleLinear } from "@visx/scale";
      5 |
      6 | import type { PriceDataPoint } from "./types";

      at Runtime.createScriptFromCode (../../node_modules/.pnpm/jest-runtime@28.1.2/node_modules/jest-runtime/build/index.js:1796:14)
      at Object.<anonymous> (src/use-price-graph.hook.ts:3:1)

Solution

I tested this solution locally:

This library is only available as an ES module on Node (and bundlers). This will need to be fixed in Jest.