diff --git a/src/components/RefinementList/__tests__/RefinementList-test.js b/src/components/RefinementList/__tests__/RefinementList-test.js index 5c2dd5d8d0..f69162b3fb 100644 --- a/src/components/RefinementList/__tests__/RefinementList-test.js +++ b/src/components/RefinementList/__tests__/RefinementList-test.js @@ -235,7 +235,7 @@ describe('RefinementList', () => { // When const root = shallowRender(props); - const actual = root.find('Template').filter({templateKey: 'show-more-inactive'}); + const actual = root.find('[templateKey="show-more-inactive"]'); // Then expect(actual.length).toEqual(1); diff --git a/src/components/Template.js b/src/components/Template.js index 002ce0147d..730abfc12c 100644 --- a/src/components/Template.js +++ b/src/components/Template.js @@ -8,7 +8,7 @@ import hogan from 'hogan.js'; import isEqual from 'lodash/isEqual'; -class Template extends React.Component { +export class Template extends React.Component { shouldComponentUpdate(nextProps) { return !isEqual(this.props.data, nextProps.data) || this.props.templateKey !== nextProps.templateKey; } @@ -22,7 +22,7 @@ class Template extends React.Component { templateKey: this.props.templateKey, compileOptions, helpers: this.props.templatesConfig.helpers, - data: transformData(this.props.transformData, this.props.templateKey, this.props.data), + data: this.props.data, }); if (content === null) { @@ -137,4 +137,15 @@ function transformHelpersToHogan(helpers, compileOptions, data) { ); } -export default Template; +// Resolve transformData before Template, so transformData is always called +// even if the data is the same. Allowing you to dynamically inject conditions in +// transformData that will force re-rendering +const withTransformData = + TemplateToWrap => + props => + ; + +export default withTransformData(Template); diff --git a/src/components/__tests__/Template-test.js b/src/components/__tests__/Template-test.js index 0315f41f14..24f563e7ab 100644 --- a/src/components/__tests__/Template-test.js +++ b/src/components/__tests__/Template-test.js @@ -4,7 +4,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import expect from 'expect'; import TestUtils from 'react-addons-test-utils'; -import Template from '../Template'; +import TemplateWithTransformData, {Template} from '../Template'; import sinon from 'sinon'; import expectJSX from 'expect-jsx'; expect.extend(expectJSX); @@ -120,11 +120,10 @@ describe('Template', () => { }, }); - renderer.render(