这是失败的测试本身:
it('Then it should call the Uploader.uploadMedia method with a POST', async () => {
const wrapper = shallow(component);
wrapper.setState({
loadedMedia: { 'test.jpg': { Content: '1234', ContentType: 'test' } },
}, async () => {
const mockUploadMedia = jest.fn();
mockUploadMedia.mockReturnValue(Promise.resolve('POST'));
Uploader.uploadMedia = mockUploadMedia;
await simulateUserInput(wrapper);
expect(mockUploadMedia.mock.calls[0][1].method).toBe('POST');
});
});
mock函数将数据发布到以下位置:
const Uploader = {
uploadMedia: async (containerId, media, token) => {
const fetchResponse = await Fetcher.fetch(`${Settings.MediaService.URL}${containerId}`, {
body: JSON.stringify({
Content: media.content,
ContentType: media.contentType,
}),
method: 'POST',
headers: {
Authorization: `bearer ${token}`,
'Content-Type': 'application/json',
},
});
return fetchResponse.text();
},
};
令牌有效,URL指向正确的服务和目录。奇怪的是,在我们拥有的节点9.11.4测试服务器上,但是在节点10.0.0上,它失败了两个测试。我无法终生确定它们的工作状况。