Jasmine 2.0: refactoring out 1.3's runs() and waitsFor()

前端 未结 2 2051
情书的邮戳
情书的邮戳 2021-02-02 11:55

The recently released Jasmine 2.0 removes the waits functions and the runs() from the Async Jasmine 1.3.

I have old 1.3 tests I\'d like to transition to th

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 12:14

    It is possible to use a setTimeout in your it() block.

    it("is asynchronous", function(done) {
      var isItDone = false;
      $.ajax('/some/url').success(function() { isItDone = true; });
    
      setTimeout(function(){
        expect(isItDone).toBeTrue();
        done(); // call this to finish off the it block
      }, 500);
    
    });
    

    However, I found that that slowed down my test suite dramatically so I created my own extension which recreates the polling functionality that waitsFor provided.

    https://gist.github.com/abreckner/110e28897d42126a3bb9

提交回复
热议问题