From 23c5cac957bee0c124a389316f6f2f2a1970ece9 Mon Sep 17 00:00:00 2001 From: edoroshenko Date: Fri, 24 Nov 2017 11:36:58 +0100 Subject: [PATCH] Fix SSR (set DEFAULT_COLUMNS_COUNT to the state on init, cover SSR with unit test) --- .travis.yml | 3 +++ package.json | 9 ++++++--- src/ResponsiveMasonry.js | 2 +- src/__tests__/ResponsiveMasonry.spec.js | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 .travis.yml create mode 100644 src/__tests__/ResponsiveMasonry.spec.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8ef9518 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "lts/*" \ No newline at end of file diff --git a/package.json b/package.json index 125b29c..8c521bb 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,11 @@ "eslint-plugin-import": "^2.2.0", "eslint-plugin-jsx-a11y": "^4.0.0", "eslint-plugin-react": "^6.10.3", + "jest": "^21.2.1", "npmpub": "^3.1.0", "prop-types": "^15.5.8", - "react": "^16.0.0" + "react": "^16.0.0", + "react-dom": "^16.1.1" }, "peerDependencies": { "prop-types": "^15.5.0", @@ -37,8 +39,9 @@ "scripts": { "clean": "rm -rf lib", "lint": "eslint src/", - "build": "babel ./src --out-dir ./lib --source-maps -d ./lib", + "build": "babel ./src --out-dir ./lib --source-maps -d ./lib --ignore spec.js", "prepublish": "npm run clean && npm run build", - "release": "npmpub" + "release": "npmpub", + "test": "jest" } } diff --git a/src/ResponsiveMasonry.js b/src/ResponsiveMasonry.js index 5efd1b4..632b0cc 100644 --- a/src/ResponsiveMasonry.js +++ b/src/ResponsiveMasonry.js @@ -8,7 +8,7 @@ class MasonryResponsive extends React.Component { super(props) this.state = { - columnsCount: null, + columnsCount: DEFAULT_COLUMNS_COUNT, } this.handleResize = this.handleResize.bind(this) diff --git a/src/__tests__/ResponsiveMasonry.spec.js b/src/__tests__/ResponsiveMasonry.spec.js new file mode 100644 index 0000000..363f1af --- /dev/null +++ b/src/__tests__/ResponsiveMasonry.spec.js @@ -0,0 +1,14 @@ +import React from 'react'; +import { renderToString } from 'react-dom/server'; +import Masonry, { ResponsiveMasonry } from '../'; + +describe('server-side rendering', () => { + it('should render on server', () => { + const content = 'Custom content inside ResponsiveMasonry wrapper'; + const result = renderToString( +
{content}
+
); + + expect(result.match(RegExp(content))).not.toBeNull(); + }) +});