Mailspring/packages/client-app/spec/components/injected-component-set-spec.jsx

52 lines
1.4 KiB
React
Raw Normal View History

2016-05-07 07:42:55 +08:00
/* eslint react/prefer-es6-class: "off" */
/* eslint react/prefer-stateless-function: "off" */
import {React, ComponentRegistry, NylasTestUtils} from 'nylas-exports';
import {InjectedComponentSet} from 'nylas-component-kit';
2016-10-18 08:59:33 +08:00
const {renderIntoDocument} = NylasTestUtils;
2016-05-06 13:30:34 +08:00
const reactStub = (displayName) => {
2016-05-07 07:42:55 +08:00
return React.createClass({
displayName,
2016-10-18 08:59:33 +08:00
render() { return <div className={displayName} /> },
2016-05-07 07:42:55 +08:00
});
};
describe('InjectedComponentSet', function injectedComponentSet() {
2016-05-06 13:30:34 +08:00
describe('render', () => {
beforeEach(() => {
const components = [reactStub('comp1'), reactStub('comp2')];
spyOn(ComponentRegistry, 'findComponentsMatching').andReturn(components);
});
2016-05-06 13:30:34 +08:00
it('calls `onComponentsDidRender` when all child comps have actually been rendered to the dom', () => {
let rendered;
2016-05-06 13:30:34 +08:00
const onComponentsDidRender = () => {
rendered = true;
};
2016-05-06 13:30:34 +08:00
runs(() => {
renderIntoDocument(
<InjectedComponentSet
matching={{}}
2016-05-07 05:10:28 +08:00
onComponentsDidRender={onComponentsDidRender}
/>
);
});
waitsFor(
2016-05-06 13:30:34 +08:00
() => { return rendered; },
'`onComponentsDidMount` should be called',
100
);
2016-05-06 13:30:34 +08:00
runs(() => {
expect(rendered).toBe(true);
expect(document.querySelectorAll('.comp1').length).toEqual(1);
expect(document.querySelectorAll('.comp2').length).toEqual(1);
});
});
});
});