-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
How to use contains with function props? #204
Comments
@smacker generally you'd want to do If you do that, then |
I mentioned that it's possible to move binding in constructor in some cases, but not always. Consider this examples: items.map((item) => <Input onChange={this._onInputChange.bind(this, item.type))} />
items.map((item) => <Input onChange={this._makeOnChangeCallback(item.name)} /> |
Ah, true you did. In that case, you created a new function and didn't store it anywhere else - it doesn't seem possible to locate things based on that function. You'd probably want to spy on the |
Could you please give a example with My point is, that in some cases I want to find component, but skip some props, i'll tests a behavior in other tests like: it('should contain input', () => {
expect(wrapper.contains(<Input myProp='I want to check' />)).to.equal(true);
});
it('change of input should set name state', () => {
const newValue = 'newValue';
wrapper.find(Input).props('onChange')(newValue);
expect(wrapper.getState('name')).to.equal(newValue);
}) In this case I don't care about private callbacks that were passed to component, I test only behavior. |
So, in this case, I'd do something like the following:
|
Okay, thanks. It will work: it('should render input', () => {
const wrapper = shallow(<MyComponent />);
const inputs = wrapper.find(Input);
expect(inputs.filter((input) => input.prop('myProp') === 'I want to check').to.have.length(1);
}); but it('should render input', () => {
const wrapper = shallow(<MyComponent />);
expect(wrapper.contains(<Input myProp='I want to check' />)).to.equal(true);
}); looks nicer :( |
Unfortunately there's just no way to do it cleanly in the case you mentioned (where you are forced to create a function in the render path). |
there is. expect(
wrapper.contains(<Input myProp='I want to check' />, skipProps=['onChange'])
).to.equal(true); or something like this |
hmm, interesting idea. I feel like in that case you might want |
|
Hi guys, I had exactly the same issue with It's just 2 new functions, You can look at the tests to see how to use it If you're interested, just let me know. |
contains
method makes very simple testing complex component and don't care about markup. Something like this works great:But if I have function props, it doesn't work anymore:
In some cases it is possible to make binding in constructor (then I can get function from instance and pass as prop), but not always.
Do you see any possible solution for this problem? (for example https://github.com/algolia/expect-jsx just skip all function props when compere jsx)
The text was updated successfully, but these errors were encountered: