简体   繁体   中英

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

And the following command in my 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?

In my case the code in my globalSetup was throwing silently. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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