From 1e3e1a0834b2fd69f2e92d9c1a93690ee558c86e Mon Sep 17 00:00:00 2001 From: Ovidiu Chereches Date: Sun, 17 May 2015 17:17:31 +0300 Subject: [PATCH] Only extend function props when editing fixture #12 --- src/components/component-playground.jsx | 9 ++++++++- .../components/component-playground/events.js | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/component-playground.jsx b/src/components/component-playground.jsx index 4de1b90..80f795d 100644 --- a/src/components/component-playground.jsx +++ b/src/components/component-playground.jsx @@ -361,8 +361,15 @@ module.exports = React.createClass({ newState = {fixtureUserInput: userInput}; try { + var originalFixtureContents = + this.constructor.getSelectedFixtureContents(this.props); + + // We only want to extend Function props because they can't be serialized + // and they are not part of the editor's contents var fixtureContents = - _.cloneDeep(this.constructor.getSelectedFixtureContents(this.props)); + _.pick(originalFixtureContents, function(value, key) { + return _.isFunction(value); + }); if (userInput) { _.merge(fixtureContents, JSON.parse(userInput)); diff --git a/tests/components/component-playground/events.js b/tests/components/component-playground/events.js index 641ee8e..38c774d 100644 --- a/tests/components/component-playground/events.js +++ b/tests/components/component-playground/events.js @@ -294,6 +294,9 @@ describe('ComponentPlayground component', function() { fixtures: { 'simple state': { defaultProp: true, + unserializableProp: function() { + // noop + }, nested: { nestedProp: true } @@ -309,11 +312,22 @@ describe('ComponentPlayground component', function() { render(); }); - it('should extend fixture contents with user input', function() { + it('should extend unserializable fixture contents with user input', + function() { triggerEditorChange('{"customProp": true}'); expect(component.state.fixtureContents.customProp).to.equal(true); - expect(component.state.fixtureContents.defaultProp).to.equal(true); + expect(component.state.fixtureContents.unserializableProp).to.equal( + params.components.MyComponent.fixtures['simple state'] + .unserializableProp); + }); + + it('should not extend serializable fixture contents with user input', + function() { + triggerEditorChange('{"customProp": true}'); + + expect(component.state.fixtureContents.customProp).to.equal(true); + expect(component.state.fixtureContents.defaultProp).to.equal(undefined); }); it('should not alter the original fixture contents', function() {