jest踩坑汇总

在这里插入图片描述
jest踩坑汇总_第1张图片

  • 当测试环境为node时
    testEnvironment: ‘node’
    jest踩坑汇总_第2张图片
    添加全局mock数据
Object.defineProperty(global, 'localStorage', {
  value: {
    store: {} as Record,
    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
    jest踩坑汇总_第3张图片
  1. 全局变量
    jest踩坑汇总_第4张图片

  2. 插件
    jest踩坑汇总_第5张图片

  • 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” 添加
    ],

你可能感兴趣的:(angular,开发语言)