vendredi 27 décembre 2019

Why does Sinon FakeServer does not trigger with sinon >= 7.4.1?

At foodsharing.de we have some Sinon tests. Currently there is version <7.4.1 used but I wanted to upgrade it. According to the changelog there should be no issue, still: it won't work.

Here is the test: https://gitlab.com/foodsharing-dev/foodsharing/blob/41ae6e89dfa71903ee4d57b12fe34abd0a3f5913/client/src/script.test.js#L52

What fails is the mock browser on line 53:

mockBrowser
    .expects('goTo')
    .once()
    .withArgs(`/?page=msg&cid=${conversationId}`)

The error output:

1) script
   "after each" hook for "redirects to user chat page":
 ExpectationError: Expected goTo(/?page=msg&cid=10[, ...]) once (never called)

It seems that the ajax request is never executed, or at least there is no response? I am really not sure why does this happen.

script.chat(fsId)[1] calls conv.userChat(fsid)[2] which then calls ajax.req in the script.js[3].

[1] https://gitlab.com/foodsharing-dev/foodsharing/blob/41ae6e89dfa71903ee4d57b12fe34abd0a3f5913/client/src/script.js#L249

[2] https://gitlab.com/foodsharing-dev/foodsharing/blob/41ae6e89dfa71903ee4d57b12fe34abd0a3f5913/client/src/conv.js#L63

[3] https://gitlab.com/foodsharing-dev/foodsharing/blob/41ae6e89dfa71903ee4d57b12fe34abd0a3f5913/client/src/script.js#L376

It even calls the complete callback function with version >=7.4.1 but no fail and no success callback function is called...

Any ideas what is wrong? Did Sinon change anything back then?

Aucun commentaire:

Enregistrer un commentaire