lundi 25 février 2019

Mocked func returning promise with callFake doesn't enter then()

I have same method calls and am trying to write tests to mock MyService.getSoemthing in methodB(). However, it doesn't seem to work..

methodA(): any {
    methodB().then(() => {
        do something...
    })
}

methodB(): ng.IPromise<void> {
    return MyService.getSomething(a,b,c,d,e).then((result) => {
        ...does something with result...
        doesn't returning anything
    });
}

// With MyServiceMock injected
spyOn(MyServiceMock, 'getSomething').and.callFake(() => {
    return $q.resolve(result); // result is a variable that has already been init
});

or 

spyOn(MyServiceMock, 'getSomething').and.callFake((a,b,c,d,e) => {
    return $q.resolve(result); // result is a variable that has already been init
});

// then I call my methodA and ..
methodA();

It simply won't work.. I am able to debug until the resolution of the mock, it gets to resolve the promise but never ends up inside my ** ...does something with result... **

Any ideas?

Aucun commentaire:

Enregistrer un commentaire