substantial/sinon-stub-promise

Chained THEN not working as expected

Opened this issue · 0 comments

There is a problem when I try to stub chained promises like

return async1()
    .then((res) => {
      console.log('async1 finished', res);
      return async2();
    })
    .then((res2) => {
      console.log('async2 finished', res2);
    })

The problem is that the moment I trigger .resolves() on the first stub it automatically triggers the second then.
The problem seems to be on:

  • line 59 return this;
  • line 8 if (this.resolved && !this.rejected) { - this will never be executed because all thens are triggered before a promise can be resolved which means that all chained thens are triggered on the first stub due to return this;

I created a PR #28 so you can check exactly what happens (this should not be merged).
I tried to fix this but it didn't really work out as I was hoping.
Any ideas?