繁体   English   中英

为什么开玩笑会因“组件是 2 个模块声明的一部分”而失败?

[英]Why jest fails with "component is part of the declaration of 2 modules"?

我在 angular (nx) 项目中执行测试时遇到以下异常:

Error: Type FooComponent is part of the declarations of 2 modules: FooComponentModule and FooComponentModule! Please consider moving FooComponent to a higher module that imports FooComponentModule and FooComponentModule. You can also create a new NgModule that exports and includes FooComponent then import that NgModule in FooComponentModule and FooComponentModule.

问题是当我使用内置的 jest 集成时,我只在 IntelliJ(2022.3.1,MacOS)中得到这个异常。 Windows 的一位同事到处都遇到这个异常。

我试图在我的测试项目中执行测试app.component.spec.ts 测试应该成功执行——不仅在 CLI 中的任何地方。 最疯狂的是:我将 IntelliJ 在内置 jest 集成中执行的命令复制到内置终端,它就可以正常工作

我真的不确定在哪里解决这个问题。 这是开玩笑的问题吗? Angular? 恩克斯? 智能?

更新:

这似乎是一个 nx 相关的问题。 我用玩笑和相同的先决条件(如 lib、路径别名)创建了一个简单干净的 angular 项目,一切都按预期进行。

更新 2:

我在 nx 仓库中创建了一个问题: https://github.com/nrwl/nx/issues/14494

这并不是主要问题的真正解决方案,但使用独立组件而不是 SCAM 组件将有助于避免异常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM