Help! Tests on an API Response using Chai-HTTP IV - PUT method

Hello everyone! Thanks in advance.
My console shows this and I’ve been seeking up for a while and can’t get why I still have this for some reason:

// running tests

expected 'res.text' to equal 'res.type'

Cannot read property 'method' of undefined

Cannot read property 'method' of undefined

// tests completed

My code so far:

   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();
        });
      });

Here is the complete solution passing all tests.

test(‘send {surname: “Colombo”}’, function(done){

   // we setup the request for you...
   chai.request(server)
    .put('/travellers')
    /** send {surname: 'Colombo'} here **/
    // .send({...})
    .end(function(err, res){
      
      /** your tests here **/
       assert.equal(res.status,200);
      assert.equal(res.type, 'application/json', "Response should be json");
       assert.equal(res.body.name , 'Cristoforo');
     assert.equal(res.body.surname, 'Colombo'); // remove this after adding tests
      
      done(); // Never forget the 'done()' callback...
    });
  });

  /** Repetition is the mother of learning. **/
  // Try it again. This time without help !!
  test('send {surname: "da Verrazzano"}', function(done) {
    /** place the chai-http request code here... **/
     chai.request(server)
    .put('/travellers')
    .send({surname: 'da Verrazzano'}) 
    /** place your tests inside the callback **/
    .end(function(err, res){
          assert.equal(res.status,200);
      assert.equal(res.type, 'application/json', "Response should be json");
       assert.equal(res.body.name , 'Giovanni');
     assert.equal(res.body.surname, 'da Verrazzano');
       
     // remove this after adding tests
    done();
    });
  });
});

});

Posting full solutions should be avoided. Its better to try and help the user in the right correction.

1 Like

ok,will keep that in mind in the future.

I tried with the exact same code, but still get the following error message:

// running tests

expected undefined to equal ‘passed’

Cannot read property ‘2’ of undefined

Cannot read property ‘1’ of undefined

Cannot read property ‘0’ of undefined

Cannot read property ‘3’ of undefined

// tests completed

What should I be looking for?
This is my code: glitch.com

ok, adding

});

at the very bottom passes the challenge :sweat_smile:

Good catch! Thank you :grinning: