我只是试图编写一个简单的测试,以便能够检查按钮是否处于禁用状态。但看起来我没有正确选择按钮。
我能知道我做错了什么吗?谢谢。
return (
<Fragment>
{(isAutomatic) && (
<div className="margin-b">
<!-- Many other nested divs here -->
</div>
)}
<div className="flex">
<!-- Many other nested divs here -->
</div>
{is_something_true && (<div id="inputAlert" className="alert-form">Alert message</div>)}
<div className="margin-2-l">
<!-- Many other nested divs here -->
</div>
<button type="submit" className="btn margin-a margin-b margin-c margin-d" disabled={canUpLoad()} onClick={() => getContent()}>Load</button>
<div className="flex padding-t">
<!-- Many other nested divs here -->
</div>
<!-- Trying to capture this button and check if it is disabled -->
<button type="submit" id="email" className="btn margin-a margin-b margin-c margin-d" disabled={false} onClick={() => getData()}>Send</button>
</Fragment>
);
我的测试
import React from 'react';
import { shallow, mount } from 'enzyme';
import MyComponent from '../../../../src/space/components/MyComponent';
const data = {
name: ''
}
describe('MyComponent tests', () => {
it('should render correctly', () => {
const wrapper = shallow(<MyComponent someData={data} />);
// also tried find('#email') and find('Button#email') not working.
const submitButton = wrapper.find('button#email');
console.log(submitButton.text()); // trying to get the value 'Send' for this button but nothing gets printed. Same for submitButton.text
// this test fails.
expect(submitButton.prop('disabled')).toBe(false);
});
});
摇曳的蔷薇
相关分类