是单元测试的新手,我只想测试位于特定目录中的文件
我如何指定我希望测试仅在特定目录下运行,而忽略其他文件
所以我已经通过npm安装了jest
"jest": "^23.6.0",
并通过
在package.json中指定了我的测试命令scripts:{
"test": "jest --verbose"
}
上面运行所有文件,但我希望它为特定目录(例如,仅最新目录)中的文件运行
我该如何进行
答案 0 :(得分:6)
添加目录名称作为参数
One or more errors occurred. (Object reference not set to an instance of an object.): AggregateException
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayProxyRequest apiGatewayRequest, ILambdaContext lambdaContext)
at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.<FunctionHandlerAsync>d__13.MoveNext()
答案 1 :(得分:5)
本文
https://bambielli.com/til/2018-09-09-moving-jest-config-out-of-root/
建议您在config.js文件中做类似的事情,我引用这篇文章:
xs
答案 2 :(得分:2)
将配置添加到package.json。
"jest": {
"testMatch": ["**/laratest/**/*.test.js"]
}
https://jestjs.io/docs/en/configuration.html#testmatch-array-string
答案 3 :(得分:2)
在 def Hello do
end
中,您可以添加要搜索的目录数组
./jest.config.js
答案 4 :(得分:1)
将numbers = [1, 1, 1, 1]
unique_numbers = list()
for number in numbers:
if number not in unique_numbers:
unique_numbers.append(number)
选项添加到您的命令中:
--rootdir
或在脚本中
jest --verbose --rootDir=laratest
我尝试在自己的项目中指定目录(即scripts:{
"test": "jest --verbose --rootDir=laratest"
}
),但没有看到预期的结果。 HTH。
答案 5 :(得分:0)
您必须是特定的,以避免运行其他具有相同名称的目录。例如,这仅运行 clients
中的测试:
yarn jest "$PWD/clients"
但这会在名为 clients
的任何文件夹中运行测试:
yarn jest clients
# also: yarn jest ./clients