[Solved] Unable to access .html in Unit Tests


I’m testing a function in a UI template and keep getting Error: Cannot find module './template.html' while trying to run.

In my test file, I import the template’s JS simply by `import { foo } from ‘PATH/template.js’. Where template.js’s first line is to import its .html.

From what I’ve read https://github.com/meteor/meteor/issues/7169 . The issue is that .html isn’t compiled on the server. That post’s solution is to wrap the test’s import statement inside a

Metero.isClient. But, I’m finding that now my test suite (meteortesting:mocha) doesn’t find the test.

Now I’m confused, the tests exist on the server, but the testing framework is technically a client running the code, right? Any workarounds for this?


meteortesting:mocha will start a webserver that allows you to run the client test in a browser. Navigate to localhost:3000 to see the client test results

It also provides the option to run client tests in a headless browser (puppeteer, selenium, nightmare, phantomJS) using the environment variable TEST_BROWSER_DRIVER.

We use in-browser tests during development, and headless for CI

Have a read of the docs here:

and here:

1 Like

Got it working. Thanks once again, coag.

But I had to use meteor test --driver-package meteortesting:mocha TEST_SERVER=0 TEST_WATCH=1 with my client tests wrapped inside if Meteor.isClient . Running wo TEST_SERVER=0 only ran server code, going to browser to view client tests just timed out.

1 Like