![](/img/trans.png)
[英]Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse
[英]Unexpected token u in JSON at position 0 at JSON.parse
我正在嘗試為包含 JSON.parse 的提交函數編寫 jest 測試用例。 下面是它的代碼和測試用例。
handleFormSubmit = (e) => {
e.preventDefault();
let requestData = JSON.parse(JSON.stringify(this.props.tempAddRequest));
if (e.target[1].value.length === 0) {
this.setState({ rrNumberFeedback: true, rrNumberErr: FIELD_ERROR });
}
}
it("should check if rr is null on clicking submit button in modal", () => {
const instance = wrapper.instance();
const e = {
target: [{ name: "branchNumber", value: "" }, { name: "rrNumber", value: "" }, { name: "crdNumber", value: "1234" }],
preventDefault: () => { }
}
instance.handleFormSubmit(e);
expect(wrapper.state('rrNumberErr')).toEqual("E");
expect(wrapper.state('rrNumberFeedback')).toEqual(true);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.