Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/components/component-playground.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
18 changes: 16 additions & 2 deletions tests/components/component-playground/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ describe('ComponentPlayground component', function() {
fixtures: {
'simple state': {
defaultProp: true,
unserializableProp: function() {
// noop
},
nested: {
nestedProp: true
}
Expand All @@ -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() {
Expand Down