How to run tests in StackBlitz?

237 Views Asked by At

Picked a sample React app on StackBlitz. How does one run unit tests?

I see many people creating an app with tests, what's the purpose if those cannot be executed?

I guess you'd need a node.js project setup in order to run those?

1

There are 1 best solutions below

0
Lin Du On BEST ANSWER

From Available environments documentation:

There are two kinds of environments that run projects in StackBlitz: EngineBlock and WebContainers. Each project in StackBlitz is tied to one or the other.

From Can I run unit tests in StackBlitz? documentation:

It is also possible to run Angular unit tests inside WebContainer-based projects, but not Engineblock-based projects.

Your project uses the EngineBlock environment, you need to use the WebContainers environment.

You can see this example, please note there is a .stackblitzrc configuration file to specify the start command. The npm run test script will be run after installing the dependencies.

{
  "installDependencies": true,
  "startCommand": "npm run test"
}