Execute code after Jasmine test failure

前端 未结 4 478
故里飘歌
故里飘歌 2021-01-12 08:15

Is it possible to do something only if a Jasmine test fails? Juxtaposed with afterEach() which executes after an it() regardless of outcome, I\'m l

4条回答
  •  再見小時候
    2021-01-12 08:55

    I'm still using Jasmine 1.2 so perhaps things are different in Jasmine 2.0.

    In your afterEach function, you should be able to access the current spec that just completed by using:

    var currentSpec = jasmine.getEnv().currentSpec;
    

    That will return an object that has many properties. One of them is how many of the embedded tests passed (results_.passedCount).

    You could test against that value and perform your logging appropriately.

    Good luck!

提交回复
热议问题