使用Jest和Enzyme运行测试。此刻测试通过了,但是当我运行npm测试报道时,某些行被覆盖了,但是最后几行丢失了
patchSourceEntity = () => {
return new Promise((resolve, reject) => {
let SourceEntityBody = {
FirmID: this.props.FirmId,
Name: this.state.Name,
ShortName: this.state.ShortName,
SourceEntityTypeID: this.state.SourceEntityTypeID ? this.state.SourceEntityTypeID.value : null
}
fetch(`${this.props.services.MasterDB.URL}/SOURCE_ENTITY?id=${this.props.entityToEdit}`, {
headers: {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': this.props.services.MasterDB.subscription_key,
"DDHFirm": this.props.user.DDHFirm,
'x-universal-firm': this.props.FirmId,
},
method: 'PATCH',
credentials: 'include',
body: JSON.stringify(SourceEntityBody),
}).then(
res => {return(validationManager.ResolveHTTPResponse(res, 'Request Successful', 'Request Failed', false))
}).then(response => {
if(!response.error) {
resolve();
} else {
reject();
}
})
})
}
我嘲笑该函数:
const patchSourceEntity = jest.fn( () => {
return new Promise((resolve, reject) => {
resolve()
})})
并调用了函数:
expect(wrapper.find('SourceEntityForm').instance().patchSourceEntity()).toBeDefined()
为了使测试覆盖率达到100%,我还可以在测试中添加些什么