Issue with Run Functional Tests on an API Response using Chai-HTTP IV - PUT method

HI FCC community
I have issue with this challenge.
I know this is simple one where we are just changing values from the previous challenge but for some reason I keep getting an error

// running tests
All tests should pass
You should test for 'res.status' to be 200
You should test for 'res.type' to be 'application/json'
You should test for 'res.body.name' to be 'Giovanni'
You should test for 'res.body.surname' to be 'da Verrazzano'
// tests completed

…yet, I know I have typed in everything exactly the same way as previous challenge.

Here is my code.

      /** Repetition is the mother of learning. **/
      // Try it again. This time without help !!
test('send {surname: "da Verrazzano"}', function(done) {
  // we setup the request for you...
  chai
    .request(server)
    .put('/travellers')
    /** send {surname: 'da Verrazzano'} here **/
    .send({ surname: 'da Verrazzano' })
    // .send({...})
    .end(function(err, res) {
      /** your tests here **/
      assert.equal(res.status, 200, 'response status should be 200');
      assert.equal(res.type, 'application/json', 'Response should be json');
      assert.equal(
        res.body.name,
        'Giovanni',
        'res.body.name should be "Giovanni"'
      );
      assert.equal(
        res.body.surname,
        'da Verrazzano',
        'res.body.surname should be "da Verrazzano"'
      );

      done(); // Never forget the 'done()' callback...
    });
});

Please, help

Hmm, I copy/pasted your code into a fresh Glitch setup and it passed, but when I went back and ran through the section in order I also was unable to get it to pass. Wondering if there might be an underlying issue in the test setup. I recommend cloning a fresh Glitch project from the starter, then trying again starting just from this exercise.

1 Like

I tried that and it does not work

@BoCode84 can you link to your Glitch project?

https://bocode-chai.glitch.me/

OK upon further inspection I think what we’re dealing with here is an instance of “callback hell”. You have a set of }); on line 175 that closes out the test case, but there are two other nested callbacks you’re still inside: suite('PUT /travellers' which is itself nested in suite('Integration tests with chai-http'. Closing those two out starting on line 176 should solve your issue.

@perezvon
What are you referring to ?
You mean closing as in }); ?

NVM
I just resolved it
Thank you !

1 Like