Я пытаюсь получить фокус поля ввода имени пользователя ввода из экземпляра формы и получил следующую ошибку:
TypeError: Невозможно прочитать свойство 'input' undefined at Object.input (C: \ HL \ spot-web \ app \ components \ LoginForm \ tests \ index.test.js: 89: 28) в Object.asyncJestTest (C: \ HL \ spot-web \ node_modules \ jest-jasmine2 \ build \ jasmine_async.js: 108: 37) при разрешении (C: \ HL \ spot-web \ node_modules \ jest-jasmine2 \ build \ queue_runner.js: 56: 12) при новом Promise () в преобразователе (C: \ HL \ spot-web \ node_modules \ jest-jasmine2 \ build \ queue_runner.js: 43: 19) в обещании.process._tickCallback (внутренний / process / next_tick.js: 188: 7)
describe('<LoginForm />', () => {
it('renders', () => {
const form = shallow(
<LoginForm
username=""
password="pass"
onUsernameChange={jest.fn()}
onPasswordChange={jest.fn()}
onSubmit={jest.fn()}
loading={false}
error={false}
/>,
);
expect(form).toBeDefined();
expect(form.html()).not.toBeNull();
expect(form.html()).toMatch('Sign In');
});
it('renders loading state', () => {
const form = shallow(
<LoginForm
username=""
password=""
onUsernameChange={jest.fn()}
onPasswordChange={jest.fn()}
onSubmit={jest.fn()}
loading
error={false}
/>,
);
expect(form.html()).toMatch('Signing In');
});
it('renders error state', () => {
const form = shallow(
<LoginForm
username=""
password=""
onUsernameChange={jest.fn()}
onPasswordChange={jest.fn()}
onSubmit={jest.fn()}
loading={false}
error
/>,
);
expect(form.html()).toMatch('Wrong username or password');
});
it('show a link to recover your password', () => {
const form = shallow(
<LoginForm
username=""
password=""
onUsernameChange={jest.fn()}
onPasswordChange={jest.fn()}
onSubmit={jest.fn()}
loading={false}
error
/>,
);
expect(form.html()).toMatch('Forgot my password');
});
it('focuses on the username input after error', () => {
const form = mount(
<LoginForm
username="whatevs"
password=""
onUsernameChange={jest.fn()}
onPasswordChange={jest.fn()}
onSubmit={jest.fn()}
loading={false}
error={false}
/>,
);
const instance = form.instance();
instance.usernameInput.input.focus = jest.fn();
form.setProps({ error: true });
jest.runAllTimers();
expect(instance.usernameInput.input.focus).toHaveBeenCalledTimes(1);
});
});