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

[test] Document where the value for SwitchBase#value comes from #28638

Merged
merged 1 commit into from
Sep 28, 2021

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Sep 27, 2021

Just a quick follow-up to #28423 that adds a bit of clarity to why value is the way it is.

@eps1lon eps1lon added test component: switch This is the name of the generic UI component, not the React module! labels Sep 27, 2021
const { getByRole } = render(
<SwitchBase icon="unchecked" checkedIcon="checked" type="checkbox" value="off" />,
Copy link
Member Author

Choose a reason for hiding this comment

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

That's just encoding double negation i.e. if the input is not submitted, then it's not off. I just assume that nobody would want to write it that way so let's use a more reasonable use-case.

@mui-pr-bot
Copy link

mui-pr-bot commented Sep 27, 2021

No bundle size changes

Generated by 🚫 dangerJS against 82807a4

const { getByRole } = render(
<SwitchBase icon="unchecked" checkedIcon="checked" type="checkbox" />,
);

expect(getByRole('checkbox')).not.to.have.property('value', '');
// https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default-on
expect(getByRole('checkbox')).to.have.property('value', 'on');
Copy link
Member Author

Choose a reason for hiding this comment

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

negative assertions are good when we don't care about what a value is. But here we actually do care because ' ' should fail as well.

@eps1lon eps1lon merged commit 99a8e58 into mui:master Sep 28, 2021
@eps1lon eps1lon deleted the test/SwitchBase/default-value branch September 28, 2021 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: switch This is the name of the generic UI component, not the React module! test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants