This extension declares a debug and calls it on the next line for you.
This extension is available for free in the Visual Studio Code Marketplace. If the keyboard shortcuts need to change please set the keyboard shortcut instructions (below) to swap out a value.
- Inside where you are declaring rtl queries, press
Cmd+Ctrl+B
(Mac), orCtrl+Alt+B
(Windows) - The output will be a comma and a debug, and (on a new line) a debug that's called.
debug();
By default the keyboard shortcut is Cmd+Ctrl+B
or Ctrl+Alt+B
If this shortcut interferes with another extension or system wide Shortcut, you may change it in the Keyboard Shortcuts Setting
.
Press Cmd+P
or Ctrl+P
and type in Open Keyboard Shortcuts
.
Search for Log Javascript Selection
and click on the pen icon
.
This is where you can enter any Shortcut
you choose.
I released a breaking change in July 2021. It's entirely unclear to me that anyone relies on this extension, so I did so without warning. If you do rely on this exension please let me know. In the future I won't just randomly break the keyboard shortcuts.
There's a helpful pattern for testing where you can setup each test component with default props, then update the props as you go. This looks something like:
describe('<Example />', () => {
const setup = overrides => {
const props = {
title: "some title",
...overrides
}
const R = render(<Example {...props} />)
return {
...R,
props
}
}
it('renders the provided title', () => {
const { getByText } = setup('Override title!')
expect(getByText('Override title!')).toBeInTheDocument()
})
Since I use this all the time, I've added the keyboard shortcuts for the setup function and props. They are:
Cmd+Ctrl+J or Ctrl+Alt+J // destructures and logs props just like debug
Cmd+Ctrl+H or Ctrl+Alt+H // create a setup function stub
Strictly for personal use I've added a debug wrapping statement with
Cmd+Ctrl+U or Ctrl+Alt+U // wraps in a util
Cmd+Ctrl+C or Ctrl+Alt+C // color wrapts the selected text
Breaking change to move commands to cmd + ctrl + [blah]
. This is because there are fewer default keyboard shortcuts there.
fix output bug
add color
and util
selectors
remove .spec
Fix leading slash
When you use the setup
function you now get the file name of your current file as the component name.
Add props logging and setup function generation
Initial release of React Testing Library - Quick Debug
Open the extension in vscode, hit f5
. This should open a seperate editor that is the compiled version of your code!
In the new instace you can use the extension. In the debug console of the extension code instance you can see the debugger.