Jest stop test suite after first fail

后端 未结 3 1428
清酒与你
清酒与你 2020-12-20 11:12

I am using Jest for testing.

What I want, is to stop executing the current test suite when a test in that test suite fails.

The option --bail is

3条回答
  •  余生分开走
    2020-12-20 11:28

    hack the global.jasmine.currentEnv_.fail works for me.

          describe('Name of the group', () => {
    
            beforeAll(() => {
    
              global.__CASE_FAILED__= false
    
              global.jasmine.currentEnv_.fail = new Proxy(global.jasmine.currentEnv_.fail,{
                apply(target, that, args) {
                  global.__CASE__FAILED__ = true
                  // you also can record the failed info...
                  target.apply(that, args)
                  }
                }
              )
    
            })
    
            afterAll(async () => {
              if(global.__CASE_FAILED__) {
                console.log("there are some case failed");
                // TODO ...
              }
            })
    
            it("should xxxx", async () => {
              // TODO ...
              expect(false).toBe(true)
            })
          });
    

提交回复
热议问题