简体   繁体   English

用 globalsetup 开玩笑看不到测试

[英]Jest with globalsetup doesn't see tests

Say I have the following test:假设我有以下测试:

describe('foo', () => {
    it('bar', () => {
        expect(1).toBe(2)
    })
})

in a file named foo.application.test.ts在名为foo.application.test.ts的文件中

And the following command in my package.json:以及我的 package.json 中的以下命令:

jest --testRegex '.*.application.test.ts'"

Running these tests fails, as you would expect.正如您所料,运行这些测试会失败。 However, changing my command to:但是,将我的命令更改为:

jest --globalSetup ./tests/support/instantiateApplicationTests.ts --testRegex '.*.application.test.ts'"

Results in no tests being run at all ( the global setup file does exist), with the following log:导致根本没有运行任何测试(全局设置文件确实存在),日志如下:

yarn run v1.22.4
$ jest --globalSetup ./tests/support/instantiateApplicationTests.ts --testRegex '.*.application.test.ts'
✨  Done in 0.81s.

How am I misusing globalsetup here?我在这里如何滥用 globalsetup ?

In my case the code in my globalSetup was throwing silently.在我的情况下,我的 globalSetup 中的代码正在默默地抛出。 For anybody who runs across this, try adding console logs inside your global setup file to ascertain if it's running at all.对于遇到此问题的任何人,请尝试在全局设置文件中添加控制台日志以确定它是否正在运行。 If so, debug it using your favorite approach (node debuggers, logging, whatever).如果是这样,请使用您最喜欢的方法(节点调试器、日志记录等)对其进行调试。 Once I fixed my globalSetup script, my problem went away.一旦我修复了我的 globalSetup 脚本,我的问题就消失了。

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

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