1

I'm using Storybook to create stories. I want to create tests of the stories using @storybook/testing-react. However, I'm also using materialize-react which requires that materialize.min.js is loaded.

I am loading this in .storybook/preview-head.html and it works for storybook.

But when I run a test (created as in https://storybook.js.org/addons/@storybook/testing-react), I'm getting Error: Uncaught [ReferenceError: M is not defined] which I'm pretty sure means that materialize.min.js is not loaded.

How do I load an external JS file in testing library?

Matt
  • 4,261
  • 4
  • 39
  • 60

1 Answers1

0

I can achieve the above by appending the following to package.json:

  "scripts": {
    "test": "react-scripts test --setupFiles ./public/materialize.min.js",
  },

I'm not sure if this is the "best" way.

Matt
  • 4,261
  • 4
  • 39
  • 60