FormidableLabs / jest-next-dynamic

Resolve Next.js dynamic import components in Jest tests
MIT License
69 stars 7 forks source link

preload function is now under the render property #10

Closed ricardo-cantu closed 4 years ago

ricardo-cantu commented 4 years ago

latest Next release changed object shape

kylecesmat commented 4 years ago

@exogen I've tested this fix (after fixing the type error) against a next@9 application and it works great 🎉

exogen commented 4 years ago

Hmm, I can't get this to work when I upgrade the devDeps to use next@9.1.2.

$ jest
 FAIL  ./index.test.js
  ● Test suite failed to run

    Cannot find module 'next-server/dynamic' from 'NextDynamicNested.js'

    However, Jest was able to find:
        'test/NextDynamicNested.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

      1 | import React from "react";
    > 2 | import dynamic from "next/dynamic";
        | ^
      3 |
      4 | const NextDynamic = dynamic(
      5 |   () =>

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:203:17)
      at Object.<anonymous> (test/NextDynamicNested.js:2:1)

It's complaining about next-server/dynamic which may not exist anymore, but that's why we use virtual: true on the mock. Even when I take out the next-server/dynamic mock, it still throws that error. Any ideas? @kylecesmat @ricardo-cantu

exogen commented 4 years ago

Excitingly, upgrading Jest seems to fix that test suite issue...so I guess a Jest bug?

exogen commented 4 years ago

This is now published in v1.0.1.