Jest 25 causes `TypeError: Cannot read property 'message' of undefined`
markwoon opened this issue · comments
Bug
package
version: 1.1.5node
version: 12.14.1npm
(oryarn
) version: yarn 1.21.1
Relevant code or config
import React from 'react';
import {render} from '@testing-library/react';
function Test({}) {
return <a>error</a>;
}
describe('Link - broken', () => {
test('missing props', () => {
const {asFragment} = render(<Test />);
const result = asFragment().firstChild;
console.log(result.textContent);
expect(result)
.toHaveTextContent('error')
.not.toHaveAttribute('href');
});
});
What you did:
What happened (please provide anything you think will help):
This code fails after updating from Jest 24 to Jest 25 with: TypeError: Cannot read property 'message' of undefined
The problem comes from this line https://github.com/mattphillips/jest-chain/blob/master/src/chain.js#L21, because it always treats error as a match error, and when it isn't it it hides the actual (a TypeError
for example).
@markwoon, I think jest-chain itself doesn't produce your error, to see the actual error, disable jest-chain 👍
I have opened a PR which fixes it #24
I can confirm @tonivj5's analysis. Disabling jest-chain produced the real error.
I'm having this same issue using enzyme-matchers for jest, however disabling it doesn't produce any errors.
This works:
expect(SUT.find(".class")).not.toHaveClassName("yes")
expect(SUT.find(".class")).toHaveClassName("no")
This doesn't:
expect(SUT.find(".class"))
.not.toHaveClassName("yes")
.toHaveClassName("no")
The error says property 'toHaveClassName
doesn't exist on type void.
Any update regarding this? I used to use this package before upgrading to Jest 25 and would like to continue using it
At the moment, the best solution to this issue is to modify the source code to reflect the changes made in @tonivj5's PR (#24) and run patch-package
.
@imjordanxd did you figure out a solution or workaround for this?
@diegoaguilar no unfortunately not. Seems the PR to fix this is still open.
Sorry for the delay in coming to this, but should be fixed in: https://www.npmjs.com/package/jest-chain/v/1.1.6