I'm currently using Jest to unit test my React components and Typescript functions. So far, it's been a big success at reducing regressions and I am happy with the vscode Jest plugin that lets me step through the unit test code to see variable values and steps before the failure.
However, the plugin/Jest (not sure which) doesn't allow me to step through my imported functions/components I'm trying to test; the debugging step-through only works in the unit test file.
For example:
// file.tsx (file with functionality I want to test)
export function addOne(x: number) {
return x + 1; // can't step through this
}
// file.test.tsx (the test file)
import addOne from './file';
....... test set up......
it('addOne adds to 3 to get 5', () => { // obviously a failing test
const start = 3; // can only step through this file
const result = addOne(start); // step into doesn't work here, will skip over to the expect
expect(result).toBe(5);
});
This was obviously a fake example, but I can only step through the steps in file.test.tsx
and I can't step into the addOne
function and see what is happening inside it. I can only see what it returns. In order for me to get around this, I had to place console.logs for all the variables in the imported functionality files (file.tsx) and it has been a pain.
Is there a way to configure Jest (or another unit testing library for react/typescript) to be able to step through these imported functions?
Thanks
Update: I should clarify that when I mean I can't step into functions, I also mean that putting breakpoints in file.tsx doesn't work. The debugger does stop at breakpoints in file.test.tsx however, which I find strange I can't simply do the former.