Adding test cases to your code always helps in the long run, today we’re going to talk about how to debug test cases.
Do something today that your future self will thank you for
- Using our all-time favorite Console.log
it('should call touch & asyncValidate methods', () => { const component = shallow( <TrialRegistrationForm handleSubmit={mockHandleSubmit} pristine />, ); const mockFunction = jest.fn(); console.log(mockFunction); component.instance().touchAndAsyncValidate('test', '1'); expect(mockFunction).toBeCalledWith('test'); });
Using the debug() method of the wrapper with console.log
const component = shallow(<MyComponent />); console.log(component.debug());
- Using the Jest recommend way by using node
-
- Add debugger; where we want to break our test case
- Run the command in terminal
node --inspect-brk node_modules/.bin/jest --runInBand
Debugger listening on ws://127.0.0.1:9229/c5ce34bb-64f3-4a59-8246-e21168ba8e26 For help see https://nodejs.org/en/docs/inspector
- Open the link in chrome chrome://inspect
- Click on Open Dedicated DevTools for Node
- Our script will break at the debugger
-