Skip to content

Commit ce9b721

Browse files
committed
Check for existance/non-existance of placeholder wrappers in tests
1 parent b4d8013 commit ce9b721

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/components/PlaceholderWithoutTracking.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import PlaceholderWithoutTracking from './PlaceholderWithoutTracking.jsx';
1212
configure({ adapter: new Adapter() });
1313

1414
const {
15+
scryRenderedDOMComponentsWithClass,
1516
scryRenderedDOMComponentsWithTag,
1617
} = ReactTestUtils;
1718

@@ -21,9 +22,11 @@ describe('PlaceholderWithoutTracking', function() {
2122
placeholder = null,
2223
scrollPosition = { x: 0, y: 0 },
2324
style = {},
25+
className = '',
2426
} = {}) {
2527
return mount(
2628
<PlaceholderWithoutTracking
29+
className={className}
2730
onVisible={onVisible}
2831
placeholder={placeholder}
2932
scrollPosition={scrollPosition}
@@ -64,31 +67,44 @@ describe('PlaceholderWithoutTracking', function() {
6467
expect(placeholder.length).toEqual(numberOfPlaceholders);
6568
}
6669

70+
function expectPlaceholderWrappers(wrapper, numberOfPlaceholderWrappers, className) {
71+
const placeholderWrapper = scryRenderedDOMComponentsWithClass(wrapper.instance(), className);
72+
73+
expect(placeholderWrapper.length).toEqual(numberOfPlaceholderWrappers);
74+
}
75+
6776
it('renders the default placeholder when it\'s not in the viewport', function() {
77+
const className = 'placeholder-wrapper';
6878
const component = renderPlaceholderWithoutTracking({
6979
style: { marginTop: 100000 },
80+
className,
7081
});
7182

7283
expectParagraphs(component, 0);
7384
expectPlaceholders(component, 1);
85+
expectPlaceholderWrappers(component, 1, className);
7486
});
7587

7688
it('renders the prop placeholder when it\'s not in the viewport', function() {
7789
const style = { marginTop: 100000 };
90+
const className = 'placeholder-wrapper';
7891
const placeholder = (
7992
<strong style={style}></strong>
8093
);
8194
const component = renderPlaceholderWithoutTracking({
8295
placeholder,
8396
style,
97+
className,
8498
});
8599

86100
expectParagraphs(component, 0);
87101
expectPlaceholders(component, 1, 'strong');
102+
expectPlaceholderWrappers(component, 0, className);
88103
});
89104

90105
it('renders the prop placeholder (React class) when it\'s not in the viewport', function() {
91106
const style = { marginTop: 100000 };
107+
const className = 'placeholder-wrapper';
92108
class MyComponent extends React.Component {
93109
render() {
94110
return (
@@ -100,10 +116,12 @@ describe('PlaceholderWithoutTracking', function() {
100116
const component = renderPlaceholderWithoutTracking({
101117
placeholder,
102118
style,
119+
className,
103120
});
104121

105122
expectParagraphs(component, 0);
106123
expectPlaceholders(component, 1, 'strong');
124+
expectPlaceholderWrappers(component, 1, className);
107125
});
108126

109127
it('doesn\'t trigger onVisible when the image is not the viewport', function() {

0 commit comments

Comments
 (0)