jestjsstackblitz

Issues running jest tests from Stackblitz


I am having difficulties running my jest tests from stackblitz.

I have configured a start command in .stackblitzrc but my tests are not run...

My jest config is as follows:

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'jsdom',
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
  },
  moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
  setupFilesAfterEnv: ['@testing-library/jest-dom', 'src/setupTests.ts'],
};

Here is the stackblitz:

https://stackblitz.com/edit/react-74twff

Can someone please help?


Solution

  • First, the template you started out with doesn't look like it supports Web Containers. I'm not sure if there's a way to migrate it or not. In order to use Web Containers, you start with a Node-based template and add functionality to that.

    Below is a sample I put together that should get you working. You should be able to fork this and add your application's files or use it as a reference when building a new Stackblitz project.

    https://stackblitz.com/edit/webpack-5-react-starter-ahpjpn?file=src/app.test.tsx