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

Add jest unit testing to Chip component #3558

Merged
merged 3 commits into from
Nov 2, 2022
Merged

Conversation

habubey
Copy link
Contributor

@habubey habubey commented Nov 2, 2022

Feature Requests

Fix #3557 Add jest unit test to Chip component

@habubey habubey linked an issue Nov 2, 2022 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Nov 2, 2022

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

3 similar comments
@github-actions
Copy link

github-actions bot commented Nov 2, 2022

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@github-actions
Copy link

github-actions bot commented Nov 2, 2022

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@github-actions
Copy link

github-actions bot commented Nov 2, 2022

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@habubey habubey linked an issue Nov 2, 2022 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Nov 2, 2022

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

package.json Outdated Show resolved Hide resolved
components/lib/chip/Chip.spec.js Outdated Show resolved Hide resolved
components/lib/chip/Chip.spec.js Outdated Show resolved Hide resolved
habubey and others added 2 commits November 2, 2022 17:29
user-event library should move to devDependencies
check if label text is test
check if the icon value is correct
fireEvent.click(chipRemoveIcon);

expect(container.getElementsByClassName('p-chip-remove-icon pi pi-times-circle').length).toBe(0);
expect(removeOn).toHaveBeenCalledTimes(1);
Copy link
Member

@melloware melloware Nov 2, 2022

Choose a reason for hiding this comment

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

We can decide as a team or @mertsincan can decide but I am big fan of "arrange act assert" so something like this.

// Arrange
const removeOn = jest.fn();
const { container } = render(<Chip removable onRemove={removeOn} />);
const chipRemoveIcon = container.getElementsByClassName('p-chip-remove-icon')[0];

// Act
fireEvent.click(chipRemoveIcon);

// Assert
expect(container.getElementsByClassName('p-chip-remove-icon pi pi-times-circle').length).toBe(0);
expect(removeOn).toHaveBeenCalledTimes(1);

only because it forces developers to properly segment and think through the test

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi, Testing library is a legit library. Buğra makes this understandable by using the right spaces. Reviews provide that too. With all due respect, I don't believe this is necessary. I wonder why you think it's necessary.

Copy link
Member

Choose a reason for hiding this comment

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

const chipImage = within(wrapper[0]).getByRole('img');

expect(chipImage.getAttribute('alt')).toBe('chip');
});
Copy link
Member

Choose a reason for hiding this comment

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

We should add a test for the imageAlt property of the Chip as well.

@melloware melloware added the Component: Test Issue or pull request is related to Component Testing label Nov 2, 2022
@melloware melloware merged commit cfd8739 into primefaces:master Nov 2, 2022
@melloware
Copy link
Member

I am going to merge this and then update some changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Test Issue or pull request is related to Component Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chip: Add test specifications
4 participants