我有一个包含LoginForm
的演示组件,当我尝试使用wrapper.debug()而不是该组件时,我使用redux connect ...来查看该组件是否在那里:{{ 1}}
要查看实际的LoginForm并测试其长度,我该怎么做?
这是我的组件:
<Connect(Component) />
这是我的测试:
const LoginSection = ({ intl }) => (
<div className={styles.loginSection}>
<div className={styles.wrapper}>
<div className={styles.form}>
<p className={styles.title}>
<FormattedMessage
id="Dashboard.login.title"
defaultMessage="Login to an account"
/>
</p>
<LoginForm />
<p className={styles.createAccountWrapper}>
<span className={styles.dontHaveAccount}>
<FormattedMessage
id="Dashboard.login.subline"
defaultMessage="Dont have an account?"
/>
</span>
<a
className={styles.createAccount}
href={`${localeToDomainMap[intl.locale]}/register`}
>
<span className={styles.createOneHere}>
<FormattedMessage
id="Dashboard.login.createAccount"
defaultMessage="Create one here."
/>
</span>
</a>
</p>
</div>
</div>
</div>
);
这是const setup = (newProps) => {
const props = {};
const wrapper = shallow(<LoginSection {...props} />);
return {
wrapper,
props,
};
};
describe('LoginSection', () => {
test('that it contains LoginForm', () => {
const { wrapper } = setup();
console.log(wrapper.debug());
expect(wrapper.find('.loginFrom')).toEqual(1);
});
});
的结果:
wrapper.debug()