Skip to content

Conversation

@alizedebray
Copy link
Contributor

@alizedebray alizedebray commented Oct 13, 2025

๐Ÿ“„ Description

Update component utilities that will be used in the slider component.


๐Ÿ”ฎ Design review

  • Design review done
  • No design review needed

๐Ÿ“ Checklist

  • โœ… My code follows the style guidelines of this project
  • ๐Ÿ› ๏ธ I have performed a self-review of my own code
  • ๐Ÿ“„ I have made corresponding changes to the documentation
  • โš ๏ธ My changes generate no new warnings or errors
  • ๐Ÿงช I have added tests that prove my fix is effective or that my feature works
  • โœ”๏ธ New and existing unit tests pass locally with my changes

@alizedebray alizedebray requested a review from a team as a code owner October 13, 2025 13:22
@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2025

โš ๏ธ No Changeset found

Latest commit: e401a4a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@swisspost-bot
Copy link
Contributor

swisspost-bot commented Oct 13, 2025

Related Previews

@alizedebray alizedebray force-pushed the slider-component-utils branch from 6febb6f to f60963b Compare October 13, 2025 13:28
import { EMPTY_VALUES } from './property-checkers/constants';

export function isValueEmpty(value: unknown): boolean {
return EMPTY_VALUES.some(v => v === value);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest to keep the รฌsValueEmpty` function as is but change the way we compare the values.

The following would allow us to compare NaN with NaN, beside all the other values:
return EMPTY_VALUES.some(v => Object.is(v, value));

Test:

  • NaN === NaN -> false
  • Object.is(NaN, NaN) -> true

The idea behind this is, to allow editing the tested values โ€‹โ€‹without touching the test logic itself, thus minimizing the risk of regressions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We didnโ€™t notice the function wasnโ€™t working earlier because both the function and its tests were using the same EMPTY_VALUES array. As a result, NaN === NaN evaluated to true, but only because both values referred to the exact same NaN instance from that shared array. In general, itโ€™s best to decouple tests from implementation details as much as possible to avoid false negatives like this.


it('should throw error if the provided value is empty', () => {
EMPTY_VALUES.forEach(emptyValue => {
[undefined, null, '', NaN].forEach(emptyValue => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we have to update the values which are considered as "empty", we also have to update the test.
If on the other side we can keep the constant EMPTY_VALUES on both side, this is not the case and the maintenance effort can be kept at a minimum.

@sonarqubecloud
Copy link

Copy link
Contributor

@oliverschuerch oliverschuerch left a comment

Choose a reason for hiding this comment

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

You've requested my re-review yesterday, but I can't see any changes?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants