Typescript开玩笑的单元测试无法编译私有属性的默认值但会在本地传递

问题描述

我所有的Typescript单元测试都可以在本地使用Jest正常运行,但是在CI服务器上失败了。

尝试在colors属性上导入TSX文件时失败。

export class Product {
   private name: string;
   private colors: string[] = [];
}

出现此错误

Jest encountered an unexpected token
...

   colors = [];
          ^ 
SyntaxError: Unexpected token =

奇怪的是,如果我在构造函数中初始化属性值,而不是像这样的认值,则测试可以编译并运行良好。

export class Product {
   private colors: string[];
   constructor(){
      this.colors = p[];
   }
}

可能有问题吗?

  • 这可能是Typescript版本问题吗?
  • 是否可能根本不转译此文件

我正在使用babel-jest的{​​{1}}部分中配置的transform

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)