我是初学者,我必须通过自动化测试来检查一些ReactJS组件。这是我的第一个,我期望用良好的电子邮件和密码登录成功。
import React from 'react';
import ReactDOM from 'react-dom';
import Login from '../Login';
it('should log in user in valid session', () => {
const div = document.createElement('div');
request(Login)
.send({"email": "xxx@xxx.com", "password": "1234"});
ReactDOM.render(<Login message={"The user is connected"} />, div);
});
但是当我使用 npm run test 时,它会返回以下句子:
FAIL src/components/test/Login.test.js ● Test suite failed to run
TypeError: Cannot read property 'split' of undefined
at getApiHeader (src/libraries/global.js:312:77)
at Object.<anonymous> (src/libraries/global.js:325:14)
at Object.<anonymous> (src/components/Login.js:2:41)
at Object.<anonymous> (src/components/test/Login.test.js:3:40)
你知道发生了什么吗?我没有找到与我所做的相对应的答案。谢谢!