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

后端 未结 5 1365
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 18:11

My usual test case looks like

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

And Jasmine 2.0 async

5条回答
  •  爱一瞬间的悲伤
    2020-12-08 18:42

    You could write the test like that:

    describe("Some service'", function () {    
        var service;
        var data;
    
        beforeEach(function (done) {   
    
            module('app');
    
            inject(function (someService) {
                service = someService;
            });
    
            service
                .getData()
                .then(function(result) {
                    data = result;
                    done();
                });
        }); 
    
        it('should return a result', function () {  
            expect(data).toBeDefined();
        }); 
    }
    

提交回复
热议问题