简体   繁体   English

有没有办法关闭测试库中的语法突出显示

[英]Is there a way to turn off syntax highlighting in testing-library

I am using @testing-library/vue and run the tests within a build step of Sublime Text.我正在使用 @testing-library/vue 并在 Sublime Text 的构建步骤中运行测试。 The error output uses prettyDom and isn't very legible in the output window:错误 output 使用了 prettyDom 并且在 output window 中不是很清晰:

Example Output in Build Results window:构建结果 window 中的示例 Output:

     TestingLibraryElementError: Unable to find a label with the text of: /val1/

[36m<div[39m
  [33mclass[39m=[32m"Cell"[39m
  [33mdata-v-1cdb88a0[39m=[32m""[39m
  [33mstyle[39m=[32m"width: 40%;"[39m
[36m>[39m
  [36m<div[39m
    [33mclass[39m=[32m"Label"[39m
    [33mdata-v-1cdb88a0[39m=[32m""[39m
  [36m>[39m
    [0mTest Cat #1[0m
  [36m</div>[39m
  [36m<div[39m
    [33mattrs[39m=[32m"[object Object]"[39m
    [33mdata-v-088d7313[39m=[32m""[39m
    [33mdata-v-1cdb88a0[39m=[32m""[39m
    [33mform[39m=[32m"[object Object]"[39m
    [33mon[39m=[32m"[object Object]"[39m
    [33mprops[39m=[32m"[object Object]"[39m

Is there a way to turn off the syntax highlighting with an environment variable like you can to extend the output length?有没有一种方法可以像延长 output 长度一样关闭使用环境变量突出显示的语法?

Syntax highlighting is handled by the editor displaying the text.语法高亮由显示文本的编辑器处理。

In Sublime Text you can effectively remove – turn off if you like – the syntax highlighting of the current file / buffer by changing the syntax to Plain Text .在 Sublime Text 中,您可以通过将语法更改为Plain Text文本来有效地删除(如果您愿意,可以关闭)当前文件/缓冲区的语法突出显示。

You can do that by choosing Plain Text after clicking on the active syntax name on the right of the Status Bar or from the View --> Syntax menu, or by opening the Command Palette and selecting the Set Syntax: Plain Text command.您可以通过单击Status Bar右侧的活动语法名称后选择Plain Text或从View --> Syntax菜单中选择纯文本,或打开Command Palette并选择Set Syntax: Plain Text命令。

prettyDOM takes the same options as pretty-format . prettyDOM 采用与pretty-format相同的选项。 One of those options is "highlight".这些选项之一是“突出显示”。 In pretty-format it seems to be false by default, but in prettyDOM I found it's true by default.在 pretty-format 中,它似乎默认为 false,但在 prettyDOM 中,我发现它默认为 true。 You can disable it like this:您可以像这样禁用它:

prettyDOM(myDom, undefined, {highlight: false})

The apparent answer is to get Sublime Text to display the colors in the build window by using the ANSIescape plugin:显而易见的答案是使用 ANSIescape 插件让 Sublime Text 在构建 window 中显示 colors:

https://forum.sublimetext.com/t/ansi-color-codes-in-build-output/11296/16 https://packagecontrol.io/packages/ANSIescape https://forum.sublimetext.com/t/ansi-color-codes-in-build-output/11296/16 https://packagecontrol.io/packages/ANSIescape

You can set the COLORS environment variable to false to turn off colourisation.您可以将COLORS环境变量设置为false以关闭着色。 See https://testing-library.com/docs/dom-testing-library/api-debugging/参见https://testing-library.com/docs/dom-testing-library/api-debugging/

Although your question relates to the build results window in Sublime, this is a common problem in other places where the colour codes make it hard to see the actual debug output (in my case a Jenkins console output when tests fail).尽管您的问题与 Sublime 中的构建结果 window 相关,但这在其他地方是一个常见问题,颜色代码使得很难看到实际调试 output(在我的例子中是 Jenkins 控制台 output 当测试失败时)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 useFakeTimers 在玩笑/测试库中不起作用 - useFakeTimers not working in jest/testing-library 测试库自定义查询打字稿错误 - Testing-library custom query Typescript error 如何使用 Cypress 和 @testing-library/cypress 测试复选框切换, - How to test checkbox toggle with Cypress and @testing-library/cypress , ESLint 报告“在@testing-library/vue 中找不到屏幕” - ESLint reports "screen not found in @testing-library/vue" 用testing-library在JS中模拟长按鼠标左键 - Simulating a long press of mouse left button in JS with testing-library 使用 fireEvent 传递自定义事件属性(testing-library 和 jest) - pass custom event properties with fireEvent (testing-library and jest) @testing-library/react 中的 toBeInTheDocument 和 getBy* 有什么区别 - Whats the difference between toBeInTheDocument and getBy* in @testing-library/react 测试库反应模拟 function 与回调将设置 state 返回 - testing-library react mock function with callback that will set state on return 使用@testing-library/user-event 进行虚假点击 - Fake click using @testing-library/user-event testing-library 错误:mockConstructor(…): 没有从渲染返回 - testing-library Error: mockConstructor(…): Nothing was returned from render
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM