hozana / next-translate-routes

Flexible and translated routes for Next.js without custom server
MIT License
115 stars 30 forks source link

Error with unit tests #31

Closed nedimcimpohtec closed 2 years ago

nedimcimpohtec commented 2 years ago

There is page 404.tsx and unit test for the same page

import { act, render } from "test/utils";

import FourOFourPage from "../../src/pages/404";

describe.skip("<FourOFourPage>", () => {
  it("should render", () =>
    act(async () => {
      const { getByText } = render(<FourOFourPage />);

      expect(getByText("404")).toBeInTheDocument();
    }));
});

But when I try to run tests...

● Test suite failed to run

[next-translate-routes] - No translate routes data found. next-translate-routes plugin is probably missing from next.config.js

  325 | }
  326 |
> 327 | export default withTranslateRoutes(App);
      |                ^
  328 |

Note that there is skip but it still failes and there is next-translate-routes added in the config because some tests not related do pages are ok

Versions:

"next": "12.0.4" "next-translate-routes": "^1.7.1"

cvolant commented 2 years ago

@nedimcimpohtec Yes, that is because the next-translate-routes plugin automatically adds the next-translate-routes data to withTranslateRoutes. You can add this to your unit tests:

window.__NEXT_TRANSLATE_ROUTES_DATA = ntrData // see TNtrData from 'next-translate-routes/types'

To build the ntrData object, you can use the parsePageTree function from 'next-translate-routes/config'

Some additional docs are required...

cvolant commented 2 years ago

@nedimcimpohtec I added a createNtrData helper in v. 1.8.0. See how to use it in the docs.