- 当测试环境为node时
testEnvironment: ‘node’
添加全局mock数据
Object.defineProperty(global, 'localStorage', {
value: {
store: {} as Record<string, string>,
setItem(key: string, value: string) {
this.store[key] = value;
},
getItem(key: string) {
return this.store[key];
},
removeItem(key: string) {
delete this.store[key];
},
clear() {
this.store = {}
}
},
configurable: true,
})
- expect(received).toEqual(expected) // deep equality
-
全局变量
-
插件
- Property ‘fromEntries’ does not exist on type ‘ObjectConstructor’. Do you need to change your target library? Try changing the ‘lib’
compiler option to ‘es2019’ or later.
tsconfig.json文件修改配置
“lib”: [
“esnext” 添加
],