我有几个API,在这些API中,我们将描述作为有效负载的一部分传递。我使用OpenAPI生成类型记录客户端并编译针对esnext的代码。
export interface V1alphaExample {
/**
* Description of the rule for backoffice use only.
* @type {string}
* @memberof V1alphaExample
*/
description?: string;
}
export function V1alphaExampleFromJSONTyped(json: any, ignoreDiscriminator: boolean): V1alphaExample {
if ((json === undefined) || (json === null)) {
return json;
}
return {
'description': !exists(json, 'description') ? undefined : json['description'],
};
}
export function V1alphaExampleToJSON(value?: V1alphaExample | null): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {
'description': value.description,
};
}汇编成联合来文:
export function V1alphaExampleFromJSONTyped(json, ignoreDiscriminator) {
if ((json === undefined) || (json === null)) {
return json;
}
return {
'description': !exists(json, 'description') ? undefined : json['description'],
};
}
export function V1alphaExampleToJSON(value) {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
return {
'description': value.description,
};
}在我的应用程序编译过程中(使用babel +类型记录),一切都很好。然而,当使用Jest测试我的应用程序时,我得到了一些错误,例如:
无法从'V1alphaExample.js‘中找到模块’core-js/ module /es.符号.‘
我相信编译后的JS中的value.description正在触发Jest + Babel,以为我使用的是Symbol.prototype.description特性,而不是。
在使用Jest时,有什么方法可以禁用此功能吗?是否应该将description视为一个保留关键字,并禁止将其用作对象属性?
发布于 2019-12-27 16:53:16
我找到了几种解决问题的方法,但只有一种方法可以避免构建步骤:
package.json中更改了"main": "./dist/index.js", => "esnext": "./dist/index.js",,但在构建core-js时,导入并不能解决作为开发依赖于类型记录客户端包的问题--我不知道为什么需要这样做。我在我的主应用程序中将客户端安装为一个相对的file包(例如,我的包json将它作为file:../../genclient/package安装)。上面的解决方案感觉不对(第一个显然是错误的)。如果有人有更好的方法来修改我的项目中的一些配置文件,使Jest正常工作,请分享您的答案,以便我可以奖励您的分数!到目前为止,#2已经足够让我继续开发了。
其他的事情,我都没有用:
删除包--lock.json& node_modules目录,并从helpers)
transformIgnorePatterns in my jest.config.js --这是解决此问题的有效方法,但由于它的目标是esnext,它实际上需要传输https://stackoverflow.com/questions/59502859
复制相似问题