首先就是boot.ts里的settimeout(()=>{…},0),0秒的settimeout不是没有效果吗?
test('should return JSON when rejecting', done => {
...
getAjaxRequest().then(request => {
request.respondWith({
status: 400,
statusText: 'Bad Request',
responseText: '{"error": "BAD USERNAME", "code": 1}'
})
// 还有就是这里为什么也要用settimeout?
// then里面不是已经是resolve之后的值了吗?
//还是因为request.repondWith是需要等待的,所以settimeout是个固定写法?
setTimeout(() => {
expect(typeof response.data).toBe('object')
expect(response.data.error).toBe('BAD USERNAME')
expect(response.data.code).toBe(1)
done()
}, 100)
})
})