jeudi 26 mai 2016

How do you check that promise is resolved in jasmine >2.3?

I have a bunch of tests that check if a promise is resolved or rejected. In Jasmine 2.0 I could do the following:

it('should resolve promise', done => {
    viewModel.canDeactivate().then(() => {
        done();
    });
});

In this example viewModel.canDeactivate() returns the promise and I am trying to check its state. So, I am not using expectations but just call done callback in then to mark that test passed. If something is wrong I get a timeout exception and that is kind of OK to mark test as failed.

But the latest version of Jasmine does not like such tests, I am getting a lot of errors in console and they are marked as SPEC HAS NO EXPECTATIONS in the output.

How do you deal with such cases and how do you check a state of the promise? Thanks in advance!

  • I am using native promises. I know that in libraries such as Q we can inspect the state of the promise, but I do not now the same thing for the native promises.

Aucun commentaire:

Enregistrer un commentaire