admin管理员组文章数量:1323715
so im newbie with mocha-chai things in nodejs env. i dont understand why i cant get the response status while running mochajs.
here is my code :
let chai = require('chai');
let chaiHttp = require('chai-http');
let server = require('server');
let expect = require("chai").expect;
let should = require("should");
let request = require("superagent");
let util = require("util");
chai.use(chaiHttp);
describe('API Clinic Test', function() {
it('should list ALL clinic on /api/v1/clinic GET', function(done) {
chai.request(server)
.get('http://localhost:5000/api/v1/clinic')
.end(function(err, res){
// res.should.have.status(200);
expect(res.status).to.equal(200);
done();
});
});
it('should list a SINGLE clinic on /api/v1/clinic/<id> GET');
it('should add a SINGLE clinic on /api/v1/clinic POST');
it('should update a SINGLE clinic on /api/v1/clinic/<id> PUT');
it('should delete a SINGLE clinic on /api/v1/clinic/<id> DELETE');
});
everytime i run mocha test.js, i always get this error msg :
Uncaught TypeError: Cannot read property 'status' of undefined
ohya, i use should method too. i got another error msg like : cannot-read-property-should-of-null
i read on this thread.
Should js Cannot read property 'should' of null
thats why i want to change and use expect method.
can you guys please help me.
thank you.
::: update ::: how to fix the issue ? instead of using this line of codes :
it('should list ALL clinic on /api/v1/clinic GET', function(done) {
chai.request(server)
.get('http://localhost:5000/api/v1/clinic')
.end(function(err, res){
// res.should.have.status(200);
expect(res.status).to.equal(200);
done();
});
});
i use this :
it('should list ALL clinic on /api/v1/clinic GET', function(done) {
chai.request('localhost:5000') .get('/api/v1/clinic')
.end(function(err, res){
// res.should.have.status(200);
expect(res.status).to.equal(200);
done();
});
});
so im newbie with mocha-chai things in nodejs env. i dont understand why i cant get the response status while running mochajs.
here is my code :
let chai = require('chai');
let chaiHttp = require('chai-http');
let server = require('server');
let expect = require("chai").expect;
let should = require("should");
let request = require("superagent");
let util = require("util");
chai.use(chaiHttp);
describe('API Clinic Test', function() {
it('should list ALL clinic on /api/v1/clinic GET', function(done) {
chai.request(server)
.get('http://localhost:5000/api/v1/clinic')
.end(function(err, res){
// res.should.have.status(200);
expect(res.status).to.equal(200);
done();
});
});
it('should list a SINGLE clinic on /api/v1/clinic/<id> GET');
it('should add a SINGLE clinic on /api/v1/clinic POST');
it('should update a SINGLE clinic on /api/v1/clinic/<id> PUT');
it('should delete a SINGLE clinic on /api/v1/clinic/<id> DELETE');
});
everytime i run mocha test.js, i always get this error msg :
Uncaught TypeError: Cannot read property 'status' of undefined
ohya, i use should method too. i got another error msg like : cannot-read-property-should-of-null
i read on this thread.
Should js Cannot read property 'should' of null
thats why i want to change and use expect method.
can you guys please help me.
thank you.
::: update ::: how to fix the issue ? instead of using this line of codes :
it('should list ALL clinic on /api/v1/clinic GET', function(done) {
chai.request(server)
.get('http://localhost:5000/api/v1/clinic')
.end(function(err, res){
// res.should.have.status(200);
expect(res.status).to.equal(200);
done();
});
});
i use this :
it('should list ALL clinic on /api/v1/clinic GET', function(done) {
chai.request('localhost:5000') .get('/api/v1/clinic')
.end(function(err, res){
// res.should.have.status(200);
expect(res.status).to.equal(200);
done();
});
});
Share
Improve this question
edited May 23, 2017 at 12:13
CommunityBot
11 silver badge
asked Jan 5, 2017 at 18:49
gutasaputragutasaputra
1791 gold badge7 silver badges20 bronze badges
1
-
This just means that your
res
object is undefined, so it doesn't have any properties, includingstatus
-- i.e., your result isn't ing back. can you issue a simple GET to your target from the mand line and confirm that it responds with a 200? – meatspace Commented Jan 5, 2017 at 18:53
2 Answers
Reset to default 2you are hitting an error most likely...you should have a line similar to the below
if(err) done(err);
Per ments...this led you in the right direction. Moreso you needed to do the below:
chai.request('http://localhost:5000').get('/api/v1/clinic')
In my case I forgot to export module like export defaul mymodule
. So check for this.
本文标签: javascriptCannot read property 39status39 of undefinedMocha ChaiStack Overflow
版权声明:本文标题:javascript - Cannot read property 'status' of undefined - Mocha Chai - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742125716a2421930.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论