VS 代码将 'it' 变成 'hasUncaughtExceptionCaptureCallback'。如何禁用它?
VS code turns 'it' into 'hasUncaughtExceptionCaptureCallback'. How to disable this?
我正在阅读一本关于 React 中的测试驱动开发的书。我以前从未编写过 JavaScript 测试。作者在标题为 calc.test.js
:
的文件中提供了以下 Jest 代码
var add = require('./calc.js')
describe('calculator',function() {
it('add two numbers',function() {
expect(add(1,2)).toEqual(3)
})
})
但 VS 代码自动将其转换为:
const { hasUncaughtExceptionCaptureCallback } = require('process')
const { isTypedArray } = require('util/types')
var add = require('./calc.js')
describe('calculator', function () {
isTypedArray('add two numbers', function () {
hasUncaughtExceptionCaptureCallback(add(1, 2).toEqual(3))
})
})
作者声明他的版本使用“借自”jasmine 的语法。这就是 VS Code 改变它的原因吗?如何关闭此功能? Jest 已安装。
似乎 vscode 尝试自动完成 it
和 expect
,并自动导入模块 process
和 utils/types
。
尽管根据 jest documentation:
不需要手动导入
In your test files, Jest puts each of these methods and objects into
the global environment. You don't have to require or import anything
to use them. However, if you prefer explicit imports, you can do
import {describe, expect, test} from '@jest/globals'.
您可以通过显式导入来消除 vscode 警告:
import {describe, expect, test} from '@jest/globals'
我正在阅读一本关于 React 中的测试驱动开发的书。我以前从未编写过 JavaScript 测试。作者在标题为 calc.test.js
:
var add = require('./calc.js')
describe('calculator',function() {
it('add two numbers',function() {
expect(add(1,2)).toEqual(3)
})
})
但 VS 代码自动将其转换为:
const { hasUncaughtExceptionCaptureCallback } = require('process')
const { isTypedArray } = require('util/types')
var add = require('./calc.js')
describe('calculator', function () {
isTypedArray('add two numbers', function () {
hasUncaughtExceptionCaptureCallback(add(1, 2).toEqual(3))
})
})
作者声明他的版本使用“借自”jasmine 的语法。这就是 VS Code 改变它的原因吗?如何关闭此功能? Jest 已安装。
似乎 vscode 尝试自动完成 it
和 expect
,并自动导入模块 process
和 utils/types
。
尽管根据 jest documentation:
In your test files, Jest puts each of these methods and objects into the global environment. You don't have to require or import anything to use them. However, if you prefer explicit imports, you can do import {describe, expect, test} from '@jest/globals'.
您可以通过显式导入来消除 vscode 警告:
import {describe, expect, test} from '@jest/globals'