Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

javascript - Jasmine 2.0 async done() and angular-mocks inject() in same test it()

My usual test case looks like

it("should send get request", inject(function(someServices) {
     //some test
}));

And Jasmine 2.0 async test should look like

it("should send get request", function(done) {
     someAsync.then(function(){
         done();
     });
});

How can I use both done and inject in one test?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This should work; I ran into the same problem when I updated to Jasmine 2.0

it("should send get request", function(done) {
    inject(function(someServices) {
        //some async test
        done();
    })(); // function returned by 'inject' has to be invoked
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...