How to reuse beforeEach/afterEach in Jasmine JS?

后端 未结 4 798
暖寄归人
暖寄归人 2020-11-29 04:19

When writing tests with JasmineJS I have many tests that have similar beforeEach/afterEach code.

Is there a way to implement an inheritance model using JasmineJS tes

4条回答
  •  清酒与你
    2020-11-29 05:04

    If you want to do this for all your suites, you can register a beforeEach or afterEach function in the topSuite:

    jasmine.getEnv().topSuite().beforeEach({fn: function() {
       //log in as admin
    }});
    

    If you only want to apply it on some suites, you can work with sub-suites:

    describe("as_admin", function() {
      beforeEach(function() {
        //log in as admin
      });
    
      describe('Services Page',function() {...});
      describe('Administrators Page',function() {...});
    
    }
    

提交回复
热议问题