vlucas / frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.

Home Page:http://frisbyjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

forget to wait for something async in your test issue, test were supposed to fail

amrsa1 opened this issue · comments

this test below supposed to fail

fit('Verify deleting last created table, API will return status code 200', async (done)=> { return frisby.timeout(timeout) .get('https://dev.sdsdsd.com/api/settings/user-settings') .inspectBody() .expect('status', 200) .then(async (res) => { const fullBody = JSON.parse(res.body); const idNum = fullBody.resultList[0].id; console.log(idNum); frisby .del('https://desdsdl.com/api/settings/user-settings/' + idNum, { body: JSON.stringify({ id: idNum }) }) .then(async () => { frisby.timeout(timeout) .get('https://desdsdl.com/api/settings/user-settings') .inspectBody() .expectNot('bodyContains', 87172) }, timeout) }, timeout) .done(done) });

frisby log shows the following

`Cannot log after tests are done. Did you forget to wait for something async in your test?

Attempted to log "
FAILURE Status: 200
JSON: {
"resultList": [
{
"id": 87170,

UnhandledPromiseRejectionWarning: Error: expectNot('bodyContains', 87172) passed and was supposed to fail
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.`

@amrkamel1

Very hard to read...

fit('Verify deleting last created table, API will return status code 200', async (done)=> {
  return frisby.timeout(timeout)
    .get('https://dev.sdsdsd.com/api/settings/user-settings')
    .inspectBody()
    .expect('status', 200)
    .then(async (res) => {
      const fullBody = JSON.parse(res.body);
      const idNum = fullBody.resultList[0].id;
      console.log(idNum);
      frisby.del('https://desdsdl.com/api/settings/user-settings/' + idNum, { body: JSON.stringify({ id: idNum }) })
        .then(async () => {
          frisby.timeout(timeout)
            .get('https://desdsdl.com/api/settings/user-settings')
            .inspectBody()
            .expectNot('bodyContains', 87172)
        }, timeout)
    }, timeout)
    .done(done)
});

@H1Gdev
Thanks for fast reply, issue has been resolved by removing done callback and add retrun to frisby in all area that i was calling only frisby

@amrkamel1

do not use done.

fit('Verify deleting last created table, API will return status code 200', async ()=> {
  return frisby.timeout(timeout)
    .get('https://dev.sdsdsd.com/api/settings/user-settings')
    .inspectBody()
    .expect('status', 200)
    .then((res) => {
      const fullBody = JSON.parse(res.body);
      const idNum = fullBody.resultList[0].id;
      console.log(idNum);
      return frisby.del('https://desdsdl.com/api/settings/user-settings/' + idNum, { body: JSON.stringify({ id: idNum }) })
        .then(() => {
          return frisby.timeout(timeout)
            .get('https://desdsdl.com/api/settings/user-settings')
            .inspectBody()
            .expectNot('bodyContains', 87172)
        }, timeout)
    }, timeout);
});

Out of curiosity, where did you learn to use the done function?

The docs and all the examples I am aware of use return: https://www.frisbyjs.com/

@vlucas thats why i was confused, there is section you may need to update

Screenshot_20200130-222704_Chrome

I feel like the explicit return is a footgun, why not suggest it('...', async () => { await frisby... })? There are lints for not awaiting promises that would catch this as well.