javascriptunit-testingjestjs

Matcher `toBeTrue` is not a function on Jest


I write a test with the following structure with framework Jest, in javascript. I receive the error TypeError: expect(...).toBeTrue is not a function:

it('should assert true', () => {
    expect(true).toBeTrue();
});

I do not know if the developers simply removed the matcher along the package life, but codacy complains about me using a substitution line expect(true).toBe(true) instead.


Solution

  • .toBeTrue() matcher is provided by jest-extended pakcage.

    You need to install it and setup.

    "jest": {
      "setupFilesAfterEnv": ["jest-extended/all"]
    }