我在我的角度项目中有玩笑测试。
\n\n我有一个 package.json 文件,指定我想用来运行测试的 jest 版本。该文件包括:
\n\n"@types/jest": "^24.0.18",\n"jest": "^24.9.0",\n"jest-preset-angular": "^7.1.1",\nRun Code Online (Sandbox Code Playgroud)\n\njest 配置还包括:
\n\n"setupFilesAfterEnv": [\n "<rootDir>/setup-jest.ts"\n],\nRun Code Online (Sandbox Code Playgroud)\n\n这就是问题发生的地方。当尝试跑步时jest,我收到以下消息:
\xe2\x97\x8f Validation Warning:\n\nUnknown option "setupFilesAfterEnv" with value ["<rootDir>/setup-jest.ts"] was found.\nThis is probably a typing mistake. Fixing it will remove this message.\n\nConfiguration Documentation:\nhttps://jestjs.io/docs/configuration.html\nRun Code Online (Sandbox Code Playgroud)\n\n我看了一下jest -h,发现了一个标志,它为我提供了笑话环境的设置。
jest --showConfig\nRun Code Online (Sandbox Code Playgroud)\n\n然而,这表明我正在版本上运行笑话
\n\n"version": "23.6.0"\nRun Code Online (Sandbox Code Playgroud)\n\n所以我的问题就在这里。为什么在我做了之后npm i,尝试运行测试的笑话版本是不同的/旧的。
我尝试使用-gflag 和save-devflag 安装 jest-cli 。
还尝试在 VS Code 中运行测试,如果有帮助的话。
\n\n …我有这个项目,我正在努力,基本上这就是我想要实现的目标.
这就是我所拥有的:
MyObject obj = MyObject.builder()
.withValue("string")
.withAnotherValue("string")
.build();
MyObject obj = MyObject.builder()
.withValue("string")
.withAnotherValue("string")
.withField("key", "value")
.build();
Run Code Online (Sandbox Code Playgroud)
因此,步骤构建器模式强制用户按该顺序使用withValue()方法和withAnotherValue()方法.该方法field()是可选的,可以根据需要多次使用.我访问了这个网站,例如http://www.svlada.com/step-builder-pattern/
所以我想要实现的是:
MyObject obj = MyObject.builder(Type.ROCK)
.withColour("blue")
.withValue("string")
.withAnotherValue("string")
.build();
MyObject obj = MyObject.builder(Type.STONE)
.withWeight("heavy")
.withValue("string")
.withAnotherValue("string")
.withField("key", "value")
.build();
Run Code Online (Sandbox Code Playgroud)
因此,在builder()方法中,您将放置一个枚举类型,并且基于枚举,您将看到一组不同的方法.所以对于ROCK的withValue(),withAnotherValue()和withColour()现在是强制性的.但对于STONE withWeight(),withAnotherValue()并withColour()是强制性的.
我有可能这样吗?过去两天我一直在尝试解决这个问题,但我似乎无法让它为每种类型提供具体的方法.它只显示了Builder中的所有方法.
任何想法和帮助都非常感谢.
码:
枚举
public enum Type implements ParameterType<Type> {
ROCK, STONE
}
Run Code Online (Sandbox Code Playgroud)
参数类型
interface ParameterType<T> {}
Run Code Online (Sandbox Code Playgroud)
为MyObject
public class MyObject implements …Run Code Online (Sandbox Code Playgroud)