Skip to content

Commit

Permalink
tests: add SSR test
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Jan 24, 2018
1 parent 5bb0bdf commit ef4e6d8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"typescript": "^2.6.2",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.5",
"webpack-node-externals": "^1.6.0"
"webpack-node-externals": "^1.6.0",
"yaml-js": "^0.2.3"
},
"peerDependencies": {
"react": "^16.0.0",
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/ssr.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react';
import { renderToString } from 'react-dom/server';
import { Redoc, createStore } from '../';
var yaml = require('yaml-js');

import { readFileSync } from 'fs';
import { resolve } from 'path';

describe('SSR', () => {
it('should render in SSR mode', async () => {
(global as any).__DEV__ = true;
const spec = yaml.load(readFileSync(resolve(__dirname, '../../demo/openapi.yaml')));
const store = await createStore(spec, '');
expect(() => {
renderToString(<Redoc store={store} />);
}).not.toThrow();

delete (global as any).__DEV__;
});
});
2 changes: 1 addition & 1 deletion src/common-elements/perfect-scrollbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { default as PerfectScrollbarConstructor } from 'perfect-scrollbar';
import psStyles from 'perfect-scrollbar/css/perfect-scrollbar.css';
import styled, { injectGlobal } from '../styled-components';

injectGlobal`${psStyles.toString()}`;
injectGlobal`${psStyles && psStyles.toString()}`;

const StyledScrollWrapper = styled.div`
position: relative;
Expand Down
2 changes: 1 addition & 1 deletion src/components/RedocStandalone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class RedocStandalone extends React.Component<RedocStandaloneProps> {
spec: (props, _, componentName) => {
if (!props.spec && !props.specUrl) {
return new Error(
`One of props 'spec' or 'specUrlurl' was not specified in '${componentName}'.`,
`One of props 'spec' or 'specUrl' was not specified in '${componentName}'.`,
);
}
return null;
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7574,6 +7574,10 @@ yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"

yaml-js@^0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/yaml-js/-/yaml-js-0.2.3.tgz#f4cf6c1b3c784f59f55547d7dfcdd06418303291"

yargs-parser@^4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-4.2.1.tgz#29cceac0dc4f03c6c87b4a9f217dd18c9f74871c"
Expand Down

0 comments on commit ef4e6d8

Please sign in to comment.