-
Notifications
You must be signed in to change notification settings - Fork 142
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
new rule: render-result-naming-convention #170
Comments
@Belco90 I thought about this example from #165 (comment), but I don't think I agree with it:
If you're using screen (which I'm recommending by default in #169 anyway), this is actually fine if you just want to simplify rendering the same thing in separate tests. If you're not using screen, this would still be a valid smoke test, and there's still no Enzyme-style wrapper object so I believe it's still following the suggestions in the article. |
Another thing to consider is that the article alternatively suggests a I don't really like it personally, especially since screen replaces most of the use of this anyway. I suppose there could be a separate |
This is what I mentioned in the original discussions. There are two different things involved here: forcing destructuring or prefer calling it By the original discussion I thought you proposed just the first one, but actually you want both as per described in KCD post. This only reports if you keep Should we rename the rule then? I think Valid examples: // destructuring directly from render
const { rerender } = render(<Foo />);
// saving render result in view
const view = render(<Foo />);
// destructuring from method wrapping render
const setUp = () => render(<Foo />);
const { rerender } = setUp();
// saving method wrapping render result in view
const setUp = () => render(<Foo />);
const view = setUp(); Invalid examples: // saving render result in a var other than view
const wrapper = render(<Foo />);
const utils = render(<Bar />);
// saving method wrapping render result in a var other than view
const setUp = () => render(<Foo />);
const utils = setUp();
const wrapper = setUp(); |
The article seems to really prioritize destructuring over |
I like to have the possibility to keep
function renderWithRedux(ui, reduxOptions = {}, renderFn = render) {
const {
initialState,
store = createStore(reducer, initialState),
} = reduxOptions;
const view = {
...renderFn(<Provider store={store}>{ui}</Provider>),
store,
};
view.rerenderWithRedux = (newUi) =>
renderWithRedux(newUi, { store }, view.rerender);
return view;
}
const setUp = () => {
const view = render(<Foo />);
const getSomethingDynamically = val => view.getByRole('button', { name: val });
const getSomethingRepetitive = () => view.getByRole('button', { name: 'submit' };
return { getSomethingDynamically, getSomethingRepetitive, ...view }; Both cases can be rewritten destructuring |
Fair enough, those seem like valid use cases to me. However I'm not sure if they'd be common enough to warrant explicitly allowing them, vs just disabling them inline as you suggested. Do you think we could at least do an initial release that forces destructuring, or would it be too confusing? Another thing to consider is that if we end up changing our mind over time, the old rule name could get confusing and we may have to rename it (unless we choose a generic name in advance). |
I think the following should be allowed:
|
I actually use Suggestions for rule name? I think even Should the rule then fix the code if other than |
Don't know if it's possible to provide a fix, you would also need to update all the references to it. AFAIK this isn't straight forward. What about |
@timdeschryver nice one! Let's skip the fix then and rename it to |
No one got this one assigned right? I'll start working on it. |
🎉 This issue has been resolved in version 4.0.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Inspiration: Using wrapper as the variable name for the return value from render
If possible, it would be nice to extend or reuse the existing core rule
prefer-destructuring
so it only applies towrapper
or return values ofrender
.The text was updated successfully, but these errors were encountered: