[Done] Run Functional Tests on an API Response using Chai-HTTP IV - PUT method

This is the code I’ve entered for the test

test('send {surname: "da Verrazzano"}', function(done) {
        chai.request(server)
          .put('/travellers')
          .send({surname: "da Verrazzano"})
          .end(function(err, res){
        
            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();
        });
      });

And I keep getting the following result:
// running test
expected undefined to equal ‘passed’
Cannot read property ‘0’ of undefined
Cannot read property ‘1’ of undefined
Cannot read property ‘2’ of undefined
Cannot read property ‘3’ of undefined
// tests completed

But this code works for the previous test

test('send {surname: "Colombo"}',  function(done){
       
       // we setup the request for you...
       chai.request(server)
        .put('/travellers')
        .send({surname: "Colombo"})
        .end(function(err, res){
          
          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, 'Cristoforo', 'res.body.name should be "Cristoforo"');
          assert.equal(res.body.surname, 'Colombo', 'res.body.surname should be "Colombo"' );
         
          done(); 
        });
      });

What am I missing?

3 Likes

Same issue here. You have any success yet?

I mucked around and found that there’s a missing }); near the bottom. Something’s wonky with the code evaluation because when I put it at the very bottom of the page some of the tests pass, and others don’t. When I put it at the bottom of the “Functional Tests” section, some tests pass and others don’t.

Ended up creating a glitch for this section, then a separate glitch for the ‘headless browser’ challenges.

8 Likes

Type ( not copy/paste ) the solution with fingers and watch red circle in front of your test. The circle should remain unchanged.

I added }); near the bottom and I solved the issue too XD

7 Likes