Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/__tests__/functional-tests/ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ afterEach(() => {

const vrOnlyComponents = ['app-layout-toolbar'];

// Components whose entire tree is rendered through a portal. The server renderer has no
// container to portal into, so none of their content reaches the server markup. Portal
// itself renders a hidden placeholder element in its place, so that the markup matches
// the first client render and hydration succeeds; the client replaces it on the first
// commit. Older component-toolkit versions emit nothing at all, hence the optional match.
const portaledComponents = ['modal', 'tooltip'];
const emptyOrHiddenPlaceholder = /^(<span style="display:none"><\/span>)?$/;

test('ensure is it not DOM', () => {
expect(typeof window).toBe('undefined');
expect(typeof CSS).toBe('undefined');
Expand All @@ -34,9 +42,9 @@ for (const componentName of getAllComponents().filter(component => vrOnlyCompone
const { default: Component } = requireComponent(componentName);
const props = getRequiredPropsForComponent(componentName);
const content = renderToStaticMarkup(React.createElement(Component, props, 'test content'));
if (componentName === 'modal' || componentName === 'tooltip') {
// modal and tooltip use portal API which does not work on server and returns an empty content
expect(content.length).toEqual(0);
if (portaledComponents.indexOf(componentName) !== -1) {
expect(content).not.toContain('test content');
expect(content).toMatch(emptyOrHiddenPlaceholder);
} else {
expect(content.length).toBeGreaterThan(0);
}
Expand Down
Loading