是否有一个快捷方式在VS Code实现一个jest todo测试?



当我有:

test.todo('customer can order a pizza');

我想要一个快捷方式,将行转换为:

test('customer can order a pizza', async () => {
<|>
});

其中<|>为光标位置。

可以使用片段吗?理想情况下,我不希望在触发转换之前选择整行。

或者有这样的扩展吗?

您可以使用扩展名multi-command

{
"key": "alt+x",
"command": "extension.multiCommand.execute",
"args": { 
"sequence": [
"cursorEnd",
"cursorHomeSelect",
{ "command": "editor.action.insertSnippet",
"args": {
"snippet": "test(${TM_SELECTED_TEXT/test\.todo('[^']+');/'${1}'/}, async () => {\n\t$0\n\t});"
}
}
]
}
}

检查代码片段到vscode https://marketplace.visualstudio.com/items?itemName=andys8.jest-snippets

基于@rioV8的回答,我能够使它工作🎉非常感谢🙏

从命令面板打开Preferences: Open Keyboard Shortcuts (JSON),粘贴:

{
"key": "cmd+shift+i",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"cursorEnd",
"cursorHomeSelect",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "${TM_SELECTED_TEXT/(test|it)\.todo\(('[^']+'|"[^"]+")\);/$1($2/}, async () => {nt$1n});"
}
}
]
}
}

我选择了cmd+shift+i作为"实现",请随意选择您喜欢的快捷方式。

相关内容

  • 没有找到相关文章

最新更新