【发布时间】:2021-09-24 17:39:12
【问题描述】:
如何使用反应测试库访问 IonInput 字段的值。看我的例子, 如果我替换 html 文本输入而不是 IonInput 它工作正常。
import { useState } from 'react';
import { render, screen } from '@testing-library/react';
import { IonInput } from '@ionic/react';
function MyComponent() {
const [value, setValue] = useState('123');
return (
<IonInput
data-testid="test-input"
value={value}
onIonChange={(e) => setValue(e.detail.value)}
/>
);
}
describe('Test MyComponent', () => {
test('Test input change', () => {
render(<MyComponent />);
const input = screen.queryByTestId('test-input');
expect(input.value).toBe('123');
// This input.value be undefined
console.log('input.value', input.value); // undefined
});
});
【问题讨论】:
-
已经阅读,但没有提到访问离子输入值的明确方法。
标签: reactjs ionic-framework jestjs react-testing-library