Skip to content
H1Gdev edited this page Sep 9, 2026 · 16 revisions
  • Latest GitHub

Test Code

it('Test resolves.not.toThrow()', async () => {
  await expect(async function() {
    await test();
  }()).resolves.not.toThrow();
});

it('Test .rejects.toThrow()', async () => {
  await expect(async () => {
    await test();
  }).rejects.toThrow();
});

Repeat N times

it.each([...Array(3).keys()])('%i times', (n) => {
  // Test.
});

test if

const testif = condition => condition ? test : test.skip;
const itif = condition => condition ? it : it.skip;

itif(true)('test', () => {
  // Test.
});

itif(false)('skip test', () => {
  // Test.
});
  • cannot be used with test.each...

Test Result

Report

jest-html-reporters

  • Latest GitHub
npm install jest-html-reporters --save-dev
  "jest": {
    "reporters": [
      "default",
      [
        "jest-html-reporters",
        {
          "publicPath": "./html-report",
          "filename": "index.html",
          "openReport": true
        }
      ]
    ]
  },

jest-junit

  • Latest GitHub
npm install jest-junit --save-dev
  "jest": {
    "reporters": [
      "default",
      "jest-junit"
    ]
  },
  "jest-junit": {
    "outputDirectory": "<rootDir>/reports",
    "outputName": "results.xml"
  }

Coverage

npm test -- --coverage

Clone this wiki locally