How to debug jest test cases(React)? – User friendly Tech help
Adding test cases to your code always helps in the long run, today we’re going to talk about how to debug test cases.
n
n
Do something today that your future self will thank you for
n
n
- n
- Using our all-time favorite Console.logn
it('should call touch & asyncValidate methods', () => {n const component = shallow(n ,n );nn const mockFunction = jest.fn();n console.log(mockFunction);n component.instance().touchAndAsyncValidate('test', '1');nn expect(mockFunction).toBeCalledWith('test');n });
n
Using the debug() method of the wrapper with console.log
n
const component = shallow();nconsole.log(component.debug());
- Using the Jest recommend way by using noden
- n
- n
- n
- Add debugger; where we want to break our test case
- Run the command in terminaln
node --inspect-brk node_modules/.bin/jest --runInBand
n
Debugger listening on ws://127.0.0.1:9229/c5ce34bb-64f3-4a59-8246-e21168ba8e26nFor 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
n
n
n
n
n
n
n
n
n
- n
n
n