Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tap() into ShallowWrapper and ReactWrapper #299

Merged
merged 1 commit into from
Apr 13, 2016

Conversation

koba04
Copy link
Contributor

@koba04 koba04 commented Apr 7, 2016

This is similar to underscore's tap().

http://underscorejs.org/#tap

motivation

When I'm testing complex React Element tree using method chains, I sometimes would like to inject a debug code between the method chains.

wrapper
.find('.foo')
.findWhere(n => n.text() === 'bar')
// ???
.at(0)
  • Using tap()
wrapper
.find('.foo')
.findWhere(n => n.text() === 'bar')
.tap(n => console.log(n.debug())
.at(0)
  • without tap()
wrapper
.find('.foo')
.findWhere(n => n.text() === 'bar')
.map(n => {
  console.log(n.debug());
  return n;
})
.at(0)

I think this is not an essential feature, but it would be nice if enzyme has it.
How do you think about this? 👍? 👎?

Thanks.

</ul>
);
const result = wrapper.find('li').tap(spy);
expect(spy.calledOnce).to.equal(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(spy.calledWith(wrapper)).to.equal(true) might be a stronger assertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I fixed it.

@ljharb
Copy link
Member

ljharb commented Apr 7, 2016

I think this is a pretty useful feature to be sure.

@lelandrichardson
Copy link
Collaborator

I like this as well. Never knew about this w/ underscore.

@koba04 do you mind rebasing before we merge in? Thanks.

@koba04
Copy link
Contributor Author

koba04 commented Apr 13, 2016

@lelandrichardson Thank you! rebased.

@lelandrichardson lelandrichardson merged commit 8544413 into enzymejs:master Apr 13, 2016
@koba04 koba04 deleted the feature-tap-method branch April 13, 2016 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants