In another project that uses jest 26 I could do the following:
import ChildComponent from './ChildComponent';
jest.mock('./ChildComponent', () => jest.fn(() => 'ChildComponent'));
const { container, debug } = render(<ParentComponent />);
expect(ChildComponent).lastCalledWith({a, b, c});
debug() // returns `<body><div>ChildComponent</div></body>`
Now in my current project that runs jest 27 I can't mock ChildComponent like that, I need to remove jest.fn for it to work: jest.mock('./ChildComponent', () => () => 'ChildComponent');
fine, I can live with that...
But, now when I expect child to be called with abc it says: Matcher error: received value must be a mock or spy function
I can't find anything in the changelog of jest 27, has anyone run into this issue? How can I mock a react component to return a string PLUS check if called with props??