Как предотвратить мелкий рендеринг на частном компоненте с ферментом?Предотвращение мелкого рендеринга фермента на частном компоненте
Вот компонент пример:
// foo.jsx
import React from 'react';
// Private component
const FooSubtitle = ({subtitle}) => {
if (!subtitle) return null;
return <div className="foo__subtitle">{subtitle}</div>;
};
// Public component
const Foo = ({title, subtitle}) => (
<div className="foo">
<div className="foo__title">{title}</div>
<FooSubtitle subtitle={subtitle} />
</div>
);
export default Foo;
Вот моя спецификация:
// foo.spec.js
import React from 'react';
import {shallow} from 'enzyme';
import Foo from './foo.jsx';
describe('Foo',() => {
it('should render a subtitle',() => {
const wrapper = shallow(<Foo title="my title" subtitle="my subtitle" />);
// This test doesn't work, so I cannot test the render of my component
expect(wrapper.find('.foo__subtitle').length).toBe(1);
// This one works, but it is not relevant
expect(wrapper.find('FooSubtitle').length).toBe(1);
});
});
Любая идея? Большое спасибо.
'' .foo_subtitle'' должен быть '.foo__subtitle'', не так ли? – Aurora0001
Что означает u для частного компонента –
@ Aurora0001 Да, он должен!спасибо :) Но это не решает мою проблему: P – tzi