import React from 'react';
import CrudApi from '../api/CrudApi';
import nock from 'nock';
describe('CrudList Component', () => {
it('should have users', () => {
afterEach(() => {
nock.cleanAll()
})
CrudApi.getAll().then(
data => {expect(data).toHaveLength(9) // this failed
console.log(data.length) // 10}
)
});
});这是我的测试用例,它应该失败,因为getAll返回一个包含10个元素的数组。在我的控制台中,我看到测试通过了,为什么呢?

发布于 2017-02-28 00:45:04
测试表明它通过了,因为它不等待promise来解析-您需要在it函数中返回promise:
it('should have users', () => {
afterEach(() => {
nock.cleanAll()
})
return CrudApi.getAll().then(
data => {expect(data).toHaveLength(9) // this failed
console.log(data.length) // 10}
)
});https://stackoverflow.com/questions/42491103
复制相似问题