Jest

Jest is a testing framework for JavaScript and TypeScript.

Enabling XML Output

Configure Jest to produce JUnit XML output.

npm install --save-dev jest-junit

Update your Jest config (jest.config.json or similar file) to add jest-junit as a reporter.

jest.config.json

{
  "reporters": [ "default", "jest-junit" ]
}

With this configuration, Jest runs with by default output a junit.xml file in the working directory. To further configure the reporter, consult the detailed documentation on GitHub.

Test Suite Naming

The jest-junit reporter will automatically fill in values for the and name and class attributes using the description parameters to the tests. The testsuites.name is set to jest tests by default.

For example, this test:

describe('addition', () => {
  describe('positive numbers', () => {
    it('should add up', () => {
      expect(1 + 2).toBe(3);
    });
  });
});

would produce output that looks like this:

<testsuites name="jest tests">
  <testsuite name="addition">
    <testcase classname="addition positive numbers should add up" 
              name="addition positive numbers should add up">
    </testcase>
  </testsuite>
</testsuites>

The default attributes can be changed using jest-junit configuration settings.

Further Configuration

Jest is highly customizable. See more at the Jestjs.io homepage.

Last updated