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

[Suggestions] Some syntactic sugar and extensions #285

Closed
6 tasks
phanan opened this issue Dec 20, 2017 · 13 comments
Closed
6 tasks

[Suggestions] Some syntactic sugar and extensions #285

phanan opened this issue Dec 20, 2017 · 13 comments

Comments

@phanan
Copy link
Member

phanan commented Dec 20, 2017

So I've been playing around with the lib for a while and often find myself wishing for some helpers/wrappers that feel a little bit more fluent e.g.:

  • Wrappers around event triggers i.e. wrapper.find(Foo).click() as a syntactic sugar for wrapper.find(Foo).trigger('click'). Maybe we can even go as far as wrapper.click(Foo)?
  • contains(Foo, Bar, Baz)
  • containsAny(Foo, Bar, Baz)
  • has() as an alias for contains()
  • id() for attributes().id() @robcresswell
  • more to be added

What do you guys think?

@lmiller1990
Copy link
Member

If you do wrapper.trigger('click'), that already works (triggers on component root element).

Can you explain contains a little more and give an example of what you'd want to write? At the moment I write expect(wrapper.findAll(ChannelUsersModalUser)).toHaveLength(2) which seems okay.

I think has could be added.

@phanan
Copy link
Member Author

phanan commented Dec 21, 2017 via email

@phanan
Copy link
Member Author

phanan commented Dec 21, 2017 via email

@38elements
Copy link
Contributor

IMHO,
Since I do not like alias, I hope contains is removed if has is added.

@lmiller1990
Copy link
Member

I agree with @38elements - if has is more popular, we should depreciate contains. Aliases just add more API to remember. People can add them to their own projects easily enough.

I thought about this a bit more and I'm generally against this kinds of things - I think being explicit and easily understood in your tests is a worth the extra typing (or just make a snippet, most IDE/editors have that support).

@phanan
Copy link
Member Author

phanan commented Dec 22, 2017 via email

@phanan phanan closed this as completed Dec 22, 2017
@phanan phanan reopened this Dec 22, 2017
@robcresswell
Copy link
Contributor

If I might add one more to the discussion; we currently have .classes() and .attributes().id. .id() would be a nice enhancement. It seems logical to me, at least. When I was first using the lib I just assumed it would already exist.

@eddyerburgh
Copy link
Member

@robcresswell You can get the id value using the attributes method:

wrapper.attributes().id

@robcresswell
Copy link
Contributor

@eddyerburgh Yep I know, I put that in my original comment; it was just a "sugar" suggestion.

@phanan
Copy link
Member Author

phanan commented Dec 26, 2017

@robcresswell Can't say I'm using id myself (generally using IDs in components is a bad idea), but I'll add that to the list.

@eddyerburgh
Copy link
Member

(Sorry @robcresswell, I didn't see that extra id)

My opinion is that we should avoiding adding direct aliases, like has.

The API list is already large. Adding aliases will make it more difficult to browse.

I'm also not fond of adding helper methods like id, or click, that can be achieved easily with existing methods.

The more methods there are, the more maintenance there is, and the more opportunity there is for methods to get out of sync.

That said, there are some good suggestions in this thread, like contains(Foo, Bar, Baz).

I'm going to close this issue as there are too many discussion points. It will be easier to discuss these feature requests if each feature request has its own issue.

I'll start a new issue about extending contains to support multiple params. If anyone wants to continue discussing other suggestions, please create an issue.

@phanan
Copy link
Member Author

phanan commented Dec 26, 2017

@eddyerburgh While I understand and tend to agree with some of your reasons, not adding APIs because the list is already large or because there will be more maintenance is IMO not a strong enough argument.

  • If the list is large, and people still find it lacking, then it's a problem needed to be solved right there
  • Maintenance is obviously an issue, but should never be used to negate good addons, or a library will never grow.
  • The test suite should cover methods getting out of sync issue. It it doesn't – well, we have a bigger problem to worry about.

That said, I do agree that there are too many discussion points – my intention was similar to a wishlist. Will create issues/PRs once I have time i.e. back from vacation.

@robcresswell
Copy link
Contributor

@phanan I tend to use id for singular components; top level views, or side navs, for example. Where they will actually be unique; and then use classes for reusable components, so I'd disagree that they are "a bad idea" - I think that's a far too broad / generic statement.

@eddyerburgh That approach is reasonable, I can understand wanting to keep maintenance low and the API clean. Thanks for weighing in.

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

No branches or pull requests

5 participants