How can I have a beforeAll function in Jasmine ? (Not coffeeScript)

前端 未结 4 1972
半阙折子戏
半阙折子戏 2021-02-05 03:54

I need to know if there is a way to include or use a beforeAll function, or something similar, so I can login to my application and then start testing.

Right now I\'m pu

相关标签:
4条回答
  • 2021-02-05 04:14

    please use below code and configure your setting in beforeAll statement.

    describe("Top", function() {
         beforeAll(function() { 
                console.log("Example 1 Setup"); 
         });
         it('xyz',function(){
            console.log('Hi!')
         });
    });
    
    0 讨论(0)
  • 2021-02-05 04:16

    You can add this package that adds a beforeAll() and afterAll() to Jasmine.

    https://github.com/nonplus/jasmine-beforeAll

    0 讨论(0)
  • 2021-02-05 04:20

    This is now much easier. As of Jasmine 2.1 (released 14 Nov 2014), there is a beforeAll function built into the framework.

    Here are the release notes with everything that was added in 2.1. And here is the documentation explaining beforeAll and afterAll

    0 讨论(0)
  • 2021-02-05 04:22

    You can nest as many describe functions as you want. So you can do something like...

    describe("General Test", function () {
    
        function login(){
            //This code will run once at he beginning of your script
        };
    
        login();
    
        beforeEach(function () {
            //anything in here will apply to everything in each nested describe
        });
    
        describe("Specific Test", function () {
            //Applied here
        });
    
        describe("Another Specific Test", function () {
            //And here
        });
    
    
    });
    
    0 讨论(0)
提交回复
热议问题