Vue Jest 单元测试

时间:2021-05-25 05:50:52

标签: typescript unit-testing vuejs2 jestjs ts-jest

我是玩笑单元测试的新手。我有一个组件需要进行单元测试。如何将 Vue 类模型模拟或导入到我的测试中?我不确定我真的需要做什么,因为我是新手,但我得到的错误是:

TypeError: _vm.alert.statusColor is not a function

这是我的模型/alerts.ts 的样子:

export class Alerts implements AlertInterface {
  readonly id!: string
  readonly key!: string

  .....

     statusColor(type: AlertType, state: AlertState): string {
         if (type === 'RSI') {
             const config: any = {
             neutral: '#FB8C00',
             bearish: '#F44336',
             bullish: '#4CAF50',
          }
        return config[state]
         }
         return ''
      }

如何在我的笑话测试中模拟 statusColor?

0 个答案:

没有答案