fac19 / week5-FKAM

https://week5-fakm.herokuapp.com/public/index.html
0 stars 4 forks source link

Testing promises #52

Open oliverjam opened 4 years ago

oliverjam commented 4 years ago

https://github.com/fac19/week5-FKAM/blob/5f48fe017de7a7bcf805c5b947330e8fdd3c1110/src/tests/model.test.js#L21-L28

Most of your promise tests are good. However this one has an annoying bug: you're testing whether the return value of deleteListing is true. However that function returns a promise (which is an object). You need to do your testing in a .then so your assertions run after the promise resolves or rejects:

model.deleteListing
  .then(success => {
    t.ok(success); // or t.equal(success, true)
    t.end();
  })
  .catch(error => {
    t.error(error); // will fail the test if the promise rejected
    t.end();
  )}