this is the code : -
test(‘Send {surname: “Colombo”}’, function (done) {
chai
.request(server)
.put(’/travellers’)
.end(function (err, res) {
assert.equal(res.status,200)
assert.equal(res.type,'application/json')
assert.equal(res.body.name,'Cristoforo')
assert.equal(res.body.surname,'Colombo')
done()
});
});
the results:-
All tests should pass. (“this is still an x even when the tests passed”)
You should test for ‘res.status’ to be 200. done(“passed this”)
You should test for ‘res.type’ to be ‘application/json’. done(“passed this”)
You should test for ‘res.body.name’ to be ‘Cristoforo’. done (“passed this”)
You should test for ‘res.body.surname’ to be ‘Colombo’. (“passed this”)
solution: https://replit.com/@deensaleh/boilerplate-mochachai-20
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Challenge: Run Functional Tests on an API Response using Chai-HTTP III - PUT method
Link to the challenge:
Sky020
2
Welcome there,
You have not completed the previous challenges:
// #1
test('Test GET /hello with no name', function (done) {
chai
.request(server)
.get('/hello')
.end(function (err, res) {
assert.fail(res.status, 200);
assert.fail(res.text, 'hello Guest');
done();
});
});
// #2
test('Test GET /hello with your name', function (done) {
chai
.request(server)
.get('/hello?name=xy_z')
.end(function (err, res) {
assert.fail(res.status, 200);
assert.fail(res.text, 'hello xy_z');
done();
});
});
These should not be assert.fail
calls.
Hope this helps
thanks ill wok on em and see what happens.
solution: https://replit.com/@deensaleh/boilerplate-mochachai-21
this time i did all the past sections together and still no avail yet.
const chai = require(‘chai’);
const assert = chai.assert;
const server = require(’…/server’);
const chaiHttp = require(‘chai-http’);
chai.use(chaiHttp);
suite(‘Functional Tests’, function () {
this.timeout(5000);
suite(‘Integration tests with chai-http’, function () {
// #1
test(‘Test GET /hello with no name’, function (done) {
chai
.request(server)
.get(’/hello’)
.end(function (err, res) {
assert.equal(res.status, 200);
assert.equal(res.text, ‘hello Guest’);
done();
});
});
// #2
test(‘Test GET /hello with your name’, function (done) {
chai
.request(server)
.get(’/hello?name=saleh’)
.end(function (err, res) {
assert.equal(res.status, 200);
assert.equal(res.text, ‘hello saleh’);
done();
});
});
// #3
test(‘Send {surname: “Colombo”}’, function (done) {
chai
.request(server)
.put(’/travellers’)
.send({ surname: ‘Colombo’ })
.end(function (err, res) {
assert.equal(res.status,200)
assert.equal(res.type,‘application/json’)
assert.equal(res.body.name,‘Cristoforo’)
assert.equal(res.body.surname,‘Colombo’)
done();
});
});
this time it says:-
All tests should pass. (tick)
You should test for ‘res.status’ to be 200. (x)
You should test for ‘res.type’ to be ‘application/json’.(X)
You should test for ‘res.body.name’ to be ‘Cristoforo’.(X)
You should test for ‘res.body.surname’ to be ‘Colombo’.(X)
Sky020
5
Are you creating a new boilerplate for each lesson in this section? You should only be working off the single boilerplate, unless told otherwise.
Other than that, when I submit your project, it passes the tests for this lesson.
i guess it works now using the same replit now getting results right!
thanks a lot
system
Closed
7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.