diff --git a/components/lib/badge/Badge.spec.js b/components/lib/badge/Badge.spec.js
index 217c5bce6b..99f7f3a3cb 100644
--- a/components/lib/badge/Badge.spec.js
+++ b/components/lib/badge/Badge.spec.js
@@ -2,19 +2,17 @@ import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import { Badge } from './Badge';
-const snapshot = (props, name) => expect(render( ).container).toMatchSnapshot(name);
+import { snapshot } from '../../test';
describe('Badge', () => {
- test('check snapshots', () => {
- snapshot({}, 'default');
- snapshot({ value: 22 }, 'value');
- snapshot({ size: 'large' }, 'size large');
- snapshot({ size: 'xlarge' }, 'size xlarge');
- snapshot({ size: 'invalid' }, 'size invalid');
- snapshot({ severity: 'success' }, 'severity success');
- snapshot({ severity: 'info' }, 'severity info');
- snapshot({ severity: 'warning' }, 'severity warning');
- snapshot({ severity: 'danger' }, 'severity danger');
- snapshot({ severity: 'invalid' }, 'severity invalid');
- });
+ snapshot( , 'default');
+ snapshot( , 'value');
+ snapshot( , 'size large');
+ snapshot( , 'size xlarge');
+ snapshot( , 'size invalid');
+ snapshot( , 'severity success');
+ snapshot( , 'severity info');
+ snapshot( , 'severity warning');
+ snapshot( , 'severity danger');
+ snapshot( , 'severity invalid');
});
diff --git a/components/lib/badge/__snapshots__/Badge.spec.js.snap b/components/lib/badge/__snapshots__/Badge.spec.js.snap
index 5cc7fffc06..b7be21aa04 100644
--- a/components/lib/badge/__snapshots__/Badge.spec.js.snap
+++ b/components/lib/badge/__snapshots__/Badge.spec.js.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Badge check snapshots: default 1`] = `
+exports[`Badge default 1`] = `
`;
-exports[`Badge check snapshots: severity danger 1`] = `
+exports[`Badge severity danger 1`] = `
`;
-exports[`Badge check snapshots: severity info 1`] = `
+exports[`Badge severity info 1`] = `
`;
-exports[`Badge check snapshots: severity invalid 1`] = `
+exports[`Badge severity invalid 1`] = `
`;
-exports[`Badge check snapshots: severity success 1`] = `
+exports[`Badge severity success 1`] = `
`;
-exports[`Badge check snapshots: severity warning 1`] = `
+exports[`Badge severity warning 1`] = `
`;
-exports[`Badge check snapshots: size invalid 1`] = `
+exports[`Badge size invalid 1`] = `
`;
-exports[`Badge check snapshots: size large 1`] = `
+exports[`Badge size large 1`] = `
`;
-exports[`Badge check snapshots: size xlarge 1`] = `
+exports[`Badge size xlarge 1`] = `
`;
-exports[`Badge check snapshots: value 1`] = `
+exports[`Badge value 1`] = `
{
- test('when visible is false Button return null', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when visible is true Button render correctly', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when iconPos is bottom Button is vertical', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when label is empty it returns empty button', async () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when badge is true it renders Button with badge', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when badge is null it renders Button without badge', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when click the button if loading is true it renders Button with loading icon', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when click the button if loading is false it renders Button without loading icon', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when label is true it renders Button with default aria label', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when aria-label prop is not exist aria-label prop should be equal to label prop ', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when label prop is not exist label prop should be equal to aria-label prop', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
-
- test('when using badge and label the aria-label should contain both values', () => {
- // Arrange
- const { container } = render( );
-
- // Act + Assert
- expect(container).toMatchSnapshot();
- });
+import { snapshot } from '../../test';
+describe('Button', () => {
+ snapshot( , 'when visible is false Button return null');
+ snapshot( , 'when visible is true Button render correctly');
+ snapshot( , 'when iconPos is bottom Button is vertical');
+ snapshot( , 'when label is empty it returns empty button');
+ snapshot( , 'when badge is true it renders Button with badge');
+ snapshot( , 'when badge is null it renders Button without badge');
+ snapshot( , 'when click the button if loading is true it renders Button with loading icon');
+ snapshot( , 'when click the button if loading is false it renders Button without loading icon');
+ snapshot( , 'when label is true it renders Button with default aria label');
+ snapshot( , 'when aria-label prop is not exist aria-label prop should be equal to label prop ');
+ snapshot( , 'when label prop is not exist label prop should be equal to aria-label prop');
+ snapshot( , 'when using badge and label the aria-label should contain both values');
test('when using tooltip make sure the tooltip is rendered', async () => {
// Arrange
const { container } = render( );
diff --git a/components/lib/chip/Chip.spec.js b/components/lib/chip/Chip.spec.js
index 288f15999a..35846b39e8 100644
--- a/components/lib/chip/Chip.spec.js
+++ b/components/lib/chip/Chip.spec.js
@@ -2,40 +2,42 @@ import '@testing-library/jest-dom';
import { fireEvent, render } from '@testing-library/react';
import { Chip } from './Chip';
-const snapshot = (props, name) => expect(render( ).container).toMatchSnapshot(name);
+import { snapshot } from '../../test';
describe('Chip', () => {
- test('check snapshots', () => {
- snapshot({}, 'default');
- snapshot({ image: 'http://google.com/my.png' }, 'image');
- snapshot({ image: 'http://google.com/my.png', imageAlt: 'jest' }, 'image and alt');
- snapshot({ icon: 'pi pi-check' }, 'icon');
- snapshot({ label: 'jest' }, 'label');
- });
+ snapshot( , 'default');
+ snapshot( , 'image');
+ snapshot( , 'image and alt');
+ snapshot( , 'icon');
+ snapshot( , 'label');
test('when removable is true it returns with remove icon', () => {
// Arrange
const removeOn = jest.fn();
const { container } = render( );
+
+ expect(container).toMatchSnapshot('before remove');
const chipRemoveIcon = container.getElementsByClassName('p-chip-remove-icon')[0];
// Act
fireEvent.keyDown(chipRemoveIcon, { key: 'enter', keyCode: 13 });
// Assert
- expect(container.getElementsByClassName('p-chip-remove-icon pi pi-times-circle').length).toBe(0);
+ expect(container).toMatchSnapshot('after remove');
expect(removeOn).toHaveBeenCalledTimes(1);
});
test('when removable is true the chip is removed when ENTER is pressed', () => {
// Arrange
const removeOn = jest.fn();
const { container } = render( );
+
+ expect(container).toMatchSnapshot('before remove');
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(container).toMatchSnapshot('after remove');
expect(removeOn).toHaveBeenCalledTimes(1);
});
});
diff --git a/components/lib/chip/__snapshots__/Chip.spec.js.snap b/components/lib/chip/__snapshots__/Chip.spec.js.snap
index 870ee3ccfc..ff7534e993 100644
--- a/components/lib/chip/__snapshots__/Chip.spec.js.snap
+++ b/components/lib/chip/__snapshots__/Chip.spec.js.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Chip check snapshots: default 1`] = `
+exports[`Chip default 1`] = `
`;
-exports[`Chip check snapshots: icon 1`] = `
+exports[`Chip icon 1`] = `
`;
-exports[`Chip check snapshots: image 1`] = `
+exports[`Chip image 1`] = `
`;
-exports[`Chip check snapshots: image and alt 1`] = `
+exports[`Chip image and alt 1`] = `
`;
-exports[`Chip check snapshots: label 1`] = `
+exports[`Chip label 1`] = `
`;
+
+exports[`Chip when removable is true it returns with remove icon: after remove 1`] = `
`;
+
+exports[`Chip when removable is true it returns with remove icon: before remove 1`] = `
+
+`;
+
+exports[`Chip when removable is true the chip is removed when ENTER is pressed: after remove 1`] = `
`;
+
+exports[`Chip when removable is true the chip is removed when ENTER is pressed: before remove 1`] = `
+
+`;
diff --git a/components/lib/inputtext/InputText.spec.js b/components/lib/inputtext/InputText.spec.js
index 8800c0759a..7ed7a63aca 100644
--- a/components/lib/inputtext/InputText.spec.js
+++ b/components/lib/inputtext/InputText.spec.js
@@ -27,7 +27,6 @@ describe('InputText', () => {
// Act
expect(input).toBeEnabled();
- expect(input).not.toHaveClass('p-filled');
expect(input).toHaveValue('');
expect(container).toMatchSnapshot();
});
diff --git a/components/lib/inputtextarea/InputTextarea.spec.js b/components/lib/inputtextarea/InputTextarea.spec.js
index 1db3d00604..6a8882de17 100644
--- a/components/lib/inputtextarea/InputTextarea.spec.js
+++ b/components/lib/inputtextarea/InputTextarea.spec.js
@@ -40,7 +40,6 @@ describe('InputTextarea', () => {
// Act
expect(input).toBeEnabled();
- expect(input).not.toHaveClass('p-filled');
expect(container).toMatchSnapshot();
});
test('when input is is set for validation only', async () => {
diff --git a/components/test/index.js b/components/test/index.js
new file mode 100644
index 0000000000..a207cee63f
--- /dev/null
+++ b/components/test/index.js
@@ -0,0 +1,8 @@
+import '@testing-library/jest-dom';
+import { render } from '@testing-library/react';
+
+export function snapshot(element, name) {
+ test(name, () => {
+ expect(render(element).container).toMatchSnapshot();
+ });
+}