【发布时间】:2019-04-09 12:13:43
【问题描述】:
试图测试一个休息端点,但我得到了
索引页面应该呈现,你好世界
应该渲染 hello world 200:
SyntaxError: Unexpected token { in JSON at position 25
不知道我做错了什么。
引用这个
https://github.com/chaijs/chai
router.spec.js
import chai from 'chai';
import { expect } from 'chai';
import chaiHttp from 'chai-http';
import { assert } from 'assert'
import router from '../routes/';
chai.use(chaiHttp);
// simple test
// describe('Array', () => {
// it('should return -1 when the value is not present', () => {
// assert.equal([1, 2, 3].indexOf(4), -1);
// });
// });
describe('index page should render, hello world', () => {
it('should render hello world 200', () => {
return chai.request(router)
.get('/')
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.a('object');
res.body.length.should.be.eql(0);
done();
});
});
})
index.js
import express from 'express';
const app = express();
app.get('/', (req, res) => {
return res.status(200).json({
message: "Hello World"
})
})
export default app;
【问题讨论】:
标签: javascript express mocha.js chai