diff --git a/packages/web-react/src/components/Grid/__tests__/Grid.test.tsx b/packages/web-react/src/components/Grid/__tests__/Grid.test.tsx
index 5abc51db8e..b1af48a8a5 100644
--- a/packages/web-react/src/components/Grid/__tests__/Grid.test.tsx
+++ b/packages/web-react/src/components/Grid/__tests__/Grid.test.tsx
@@ -1,5 +1,5 @@
import '@testing-library/jest-dom';
-import { render } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import React from 'react';
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest';
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest';
@@ -14,54 +14,77 @@ describe('Grid', () => {
restPropsTest(Grid, 'div');
it('should render text children', () => {
- const dom = render(Hello World);
+ const text = 'Hello world';
- const element = dom.container.querySelector('div') as HTMLElement;
- expect(element.textContent).toBe('Hello World');
+ render({text});
+
+ const element = screen.getByText(text) as HTMLElement;
+
+ expect(element).toBeInTheDocument();
});
it('should have desktop cols classname', () => {
- const dom = render();
+ const testId = 'grid-test-id';
+
+ render();
+
+ const element = screen.getByTestId(testId) as HTMLElement;
- const element = dom.container.querySelector('div') as HTMLElement;
expect(element).toHaveClass('Grid--desktop--cols-3');
});
it('should have tablet cols classname', () => {
- const dom = render();
+ const testId = 'grid-test-id';
+
+ render();
+
+ const element = screen.getByTestId(testId) as HTMLElement;
- const element = dom.container.querySelector('div') as HTMLElement;
expect(element).toHaveClass('Grid--tablet--cols-3');
});
it('should have all cols classnames', () => {
- const dom = render();
+ const testId = 'grid-test-id';
+
+ render();
+
+ const element = screen.getByTestId(testId) as HTMLElement;
- const element = dom.container.querySelector('div') as HTMLElement;
expect(element).toHaveClass('Grid--cols-2');
expect(element).toHaveClass('Grid--tablet--cols-3');
expect(element).toHaveClass('Grid--desktop--cols-4');
});
it('should have cols classname', () => {
- const dom = render();
+ const testId = 'grid-test-id';
+
+ render();
+
+ const element = screen.getByTestId(testId) as HTMLElement;
- const element = dom.container.querySelector('div') as HTMLElement;
expect(element).toHaveClass('Grid--cols-2');
});
it('should render with custom spacing', () => {
- const dom = render();
+ const testId = 'grid-test-id';
+
+ render();
+
+ const element = screen.getByTestId(testId) as HTMLElement;
- const element = dom.container.querySelector('div') as HTMLElement;
expect(element).toHaveStyle({ '--grid-spacing-x': 'var(--spirit-space-600)' });
expect(element).toHaveStyle({ '--grid-spacing-y': 'var(--spirit-space-600)' });
});
it('should render with custom spacing for each breakpoint', () => {
- const dom = render();
+ const testId = 'grid-test-id';
+
+ render(
+ ,
+ );
+
+ const element = screen.getByTestId(testId) as HTMLElement;
- const element = dom.container.querySelector('div') as HTMLElement;
expect(element).toHaveStyle({ '--grid-spacing-x': 'var(--spirit-space-100)' });
expect(element).toHaveStyle({ '--grid-spacing-y': 'var(--spirit-space-100)' });
expect(element).toHaveStyle({ '--grid-spacing-x-tablet': 'var(--spirit-space-1000)' });
@@ -71,9 +94,14 @@ describe('Grid', () => {
});
it('should render with custom vertical spacing for each breakpoint', () => {
- const dom = render();
+ const testId = 'grid-test-id';
+
+ render(
+ ,
+ );
+
+ const element = screen.getByTestId(testId) as HTMLElement;
- const element = dom.container.querySelector('div') as HTMLElement;
expect(element).toHaveStyle({ '--grid-spacing-y': 'var(--spirit-space-100)' });
expect(element).toHaveStyle({ '--grid-spacing-y-tablet': 'var(--spirit-space-1000)' });
expect(element).toHaveStyle({ '--grid-spacing-y-desktop': 'var(--spirit-space-1200)' });
@@ -83,9 +111,12 @@ describe('Grid', () => {
});
it('should render with custom spacing for only one breakpoint', () => {
- const dom = render();
+ const testId = 'grid-test-id';
+
+ render();
+
+ const element = screen.getByTestId(testId) as HTMLElement;
- const element = dom.container.querySelector('div') as HTMLElement;
expect(element).toHaveStyle({ '--grid-spacing-x-tablet': 'var(--spirit-space-1000)' });
expect(element).toHaveStyle({ '--grid-spacing-y-tablet': 'var(--spirit-space-1000)' });
expect(element).not.toHaveStyle({ '--grid-spacing-x': 'var(--spirit-space-100)' });