Skip to content

Conversation

@SimeonC
Copy link
Contributor

@SimeonC SimeonC commented May 2, 2018

I don't know if this is just something a bit weird in my setup but it took me long enough to figure this out to justify creating a PR.

In my tests I found that this code did not work (using layers of mobx and formik, basically the change event is supposed to update the value of the input):

const wrapper = getWrapper();
wrapper.find('[role="gridcell"] input')
  .at(0)
  .simulate('change', {
    target: { name: 'translation.string', value: 'My new value' }
  });
expect(
  wrapper
    .find('[role="gridcell"]')
    .at(4)
).toMatchSnapshot();

But when changed to the following it did work (also calling getRootWrapper().update() didn't work either).

getWrapper()
  .find('[role="gridcell"] input')
  .at(0)
  .simulate('change', {
    target: { name: 'translation.string', value: 'My new value' }
  });
expect(
  getWrapper()
    .find('[role="gridcell"]')
    .at(4)
).toMatchSnapshot();

@ovidiuch
Copy link
Member

ovidiuch commented May 7, 2018

Hey, thanks for the tip!

Two comments:

  1. Might be a good idea to mention that Enzyme v3 requires you to call wrapper.update after a component updates (usually in response to an event, relevant thread), and the Cosmos Enzyme API tries to alleviate that by updating the wrapper whenever we request it. Which is "magical" indeed so totally worth mentioning.
  2. Can you put it in a block quote? It think it works good with notes/tips. Eg.

image

I'm surprised getRootWrapper().update() didn't work, though.

@SimeonC
Copy link
Contributor Author

SimeonC commented May 8, 2018

Thanks for the pointers, I had completely missed that that's what enzyme does now so that makes more sense. I've updated the tip to focus more on that information and added the block quote.

My theory of why getRootWrapper().update() didn't work is that the result of getWrapper() might be immutable so updating the wrapper still needs to get the new rendered one.

@ovidiuch ovidiuch merged commit 8f32545 into react-cosmos:master May 8, 2018
@ovidiuch
Copy link
Member

ovidiuch commented May 8, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants