{
expect(asFragment()).toMatchSnapshot()
})
-it('should display children', () => {
- const { getByText } = renderComponent()
-
- expect(getByText('500')).toBeInTheDocument()
-})
-
it('should apply variant styles corectly', () => {
const { asFragment } = renderComponent({
template: `
diff --git a/packages/chakra-ui-core/src/CBox/tests/CBox.test.js b/packages/chakra-ui-core/src/CBox/tests/CBox.test.js
index 61060dad..cbc4caa0 100644
--- a/packages/chakra-ui-core/src/CBox/tests/CBox.test.js
+++ b/packages/chakra-ui-core/src/CBox/tests/CBox.test.js
@@ -1,5 +1,5 @@
import CBox from '../'
-import { render } from '@/tests/test-utils'
+import { render, screen } from '@/tests/test-utils'
const renderComponent = (props) => {
const inlineAttrs = (props && props.inlineAttrs) || ''
@@ -22,9 +22,9 @@ it('should change the style', () => {
d="flex" :w="['auto']" px="5" py="5" shadow="lg"
my="5" mb="5" rounded="sm" font-family="body"
background-color="blue.200" color="blue.700"`
- const { asFragment, getByTestId } = renderComponent({ inlineAttrs })
+ const { asFragment } = renderComponent({ inlineAttrs })
- const box = getByTestId('box')
+ const box = screen.getByTestId('box')
expect(asFragment()).toMatchSnapshot()
expect(box).toHaveStyle('display: flex')
diff --git a/packages/chakra-ui-core/src/CBreadcrumb/tests/CBreadcrumb.test.js b/packages/chakra-ui-core/src/CBreadcrumb/tests/CBreadcrumb.test.js
index 4bbeaa0d..32bc26bd 100644
--- a/packages/chakra-ui-core/src/CBreadcrumb/tests/CBreadcrumb.test.js
+++ b/packages/chakra-ui-core/src/CBreadcrumb/tests/CBreadcrumb.test.js
@@ -1,5 +1,5 @@
import { CBreadcrumb, CBreadcrumbItem, CBreadcrumbLink, CBreadcrumbSeparator } from '..'
-import { render } from '@/tests/test-utils'
+import { render, screen } from '@/tests/test-utils'
const renderComponent = (props) => {
const base = {
@@ -49,7 +49,7 @@ it('should display custom seperator ', () => {
})
it('should have the proper aria-attributes', () => {
- const { getByText, getAllByRole, getByLabelText } = renderComponent({
+ renderComponent({
template: `
@@ -65,12 +65,12 @@ it('should have the proper aria-attributes', () => {
})
// surrounding `nav` has aria-label="breadcrumb"
- getByLabelText('breadcrumb', { selector: 'nav' })
+ screen.getByLabelText('breadcrumb', { selector: 'nav' })
// `isCurrentPage` link has aria-current="page"
- const currentPageLink = getByText('Contact')
+ const currentPageLink = screen.getByText('Contact')
expect(currentPageLink).toHaveAttribute('aria-current', 'page')
// separator receives presentation="role"
- expect(getAllByRole('presentation')).toHaveLength(2)
+ expect(screen.getAllByRole('presentation')).toHaveLength(2)
})
diff --git a/packages/chakra-ui-core/src/CButton/tests/CButton.test.js b/packages/chakra-ui-core/src/CButton/tests/CButton.test.js
index 2f976f9e..578394cd 100644
--- a/packages/chakra-ui-core/src/CButton/tests/CButton.test.js
+++ b/packages/chakra-ui-core/src/CButton/tests/CButton.test.js
@@ -1,5 +1,5 @@
import { CButton } from '../..'
-import { render } from '@/tests/test-utils'
+import { render, screen } from '@/tests/test-utils'
const renderComponent = (props) => {
const base = {
@@ -17,26 +17,19 @@ it('should render correctly', () => {
expect(asFragment()).toMatchSnapshot()
})
-it('should display children', () => {
- const { getByText } = renderComponent({ template: 'Works' })
- expect(getByText('Works')).toBeInTheDocument()
-})
-
it('should display button with left icon', () => {
- const { container, asFragment } = renderComponent({ template: 'Email' })
- expect(container.querySelector('button > svg')).toBeInTheDocument()
+ const { asFragment } = renderComponent({ template: 'Email' })
expect(asFragment()).toMatchSnapshot()
})
it('should display button with right icon', () => {
- const { container, asFragment } = renderComponent({ template: 'Email' })
- expect(container.querySelector('button > svg')).toBeInTheDocument()
+ const { asFragment } = renderComponent({ template: 'Email' })
expect(asFragment()).toMatchSnapshot()
})
it('should display spinner and hide text', () => {
- const { getByTestId, container } = renderComponent({ template: 'CButton' })
- const button = getByTestId('btn')
+ const { container } = renderComponent({ template: 'CButton' })
+ const button = screen.getByTestId('btn')
expect(button).toHaveAttribute('disabled')
expect(button).toHaveAttribute('aria-disabled', 'true')
@@ -47,15 +40,15 @@ it('should display spinner and hide text', () => {
})
it('should display spinner with text', () => {
- const { getByText, container } = renderComponent({ template: 'Button' })
+ const { container } = renderComponent({ template: 'Button' })
- expect(getByText('Submitting')).toBeInTheDocument()
+ expect(screen.getByText('Submitting')).toBeInTheDocument()
const spinner = container.querySelector('[data-chakra-component=CSpinner]')
expect(spinner).toBeInTheDocument()
})
it('should display a disabled button', () => {
- const { getByText } = renderComponent({ template: 'Button' })
+ renderComponent({ template: 'Button' })
- expect(getByText('Button')).toHaveAttribute('disabled')
+ expect(screen.getByText('Button')).toHaveAttribute('disabled')
})
diff --git a/packages/chakra-ui-core/src/CButtonGroup/tests/CButtonGroup.test.js b/packages/chakra-ui-core/src/CButtonGroup/tests/CButtonGroup.test.js
index f87efd27..eb6ef1a4 100644
--- a/packages/chakra-ui-core/src/CButtonGroup/tests/CButtonGroup.test.js
+++ b/packages/chakra-ui-core/src/CButtonGroup/tests/CButtonGroup.test.js
@@ -21,9 +21,3 @@ it('should render correctly', () => {
const { asFragment } = renderComponent()
expect(asFragment()).toMatchSnapshot()
})
-
-it('should display children', () => {
- const { getByText } = renderComponent()
- expect(getByText('Button1')).toBeInTheDocument()
- expect(getByText('Button2')).toBeInTheDocument()
-})
diff --git a/packages/chakra-ui-core/src/CCheckbox/tests/CCheckbox.test.js b/packages/chakra-ui-core/src/CCheckbox/tests/CCheckbox.test.js
index d91864b9..f1edcb51 100644
--- a/packages/chakra-ui-core/src/CCheckbox/tests/CCheckbox.test.js
+++ b/packages/chakra-ui-core/src/CCheckbox/tests/CCheckbox.test.js
@@ -1,5 +1,5 @@
import CCheckbox from '..'
-import { render, userEvent } from '@/tests/test-utils'
+import { render, userEvent, screen } from '@/tests/test-utils'
jest.mock('@/packages/chakra-ui-core/src/utils/generators.js', () => {
return {
@@ -13,7 +13,7 @@ const renderComponent = (props) => {
const inlineAttrs = (props && props.inlineAttrs) || ''
const base = {
components: { CCheckbox },
- template: `checkbox`,
+ template: `check`,
...props
}
return render(base)
@@ -26,42 +26,42 @@ it('should render correctly', () => {
it('should display a disabled checkbox', () => {
const inlineAttrs = 'isDisabled'
- const { getByText, container } = renderComponent({ inlineAttrs })
- const input = container.querySelector('input')
+ renderComponent({ inlineAttrs })
+ const input = screen.getByLabelText('check')
expect(input).toHaveAttribute('disabled')
- expect(getByText('checkbox').parentNode).toHaveStyle('cursor: not-allowed;')
+ expect(screen.getByText('check').parentNode).toHaveStyle('cursor: not-allowed;')
})
it('should display a checkbox with a checked state', () => {
const inlineAttrs = 'isChecked'
- const { container } = renderComponent({ inlineAttrs })
- const input = container.querySelector('input')
+ renderComponent({ inlineAttrs })
+ const input = screen.getByLabelText('check')
expect(input).toBeChecked()
})
it('should display a checkbox with an unchecked state', () => {
const inlineAttrs = ':isChecked="false"'
- const { container } = renderComponent({ inlineAttrs })
- const input = container.querySelector('input')
+ renderComponent({ inlineAttrs })
+ const input = screen.getByLabelText('check')
expect(input).not.toBeChecked()
})
it('should have a checked state when setting defaultIsChecked', () => {
const inlineAttrs = 'defaultIsChecked'
- const { container } = renderComponent({ inlineAttrs })
- const input = container.querySelector('input')
+ renderComponent({ inlineAttrs })
+ const input = screen.getByLabelText('check')
expect(input).toBeChecked()
})
test('Uncontrolled - should not check if disabled', async () => {
const inlineAttrs = 'isDisabled'
- const { container, getByText } = renderComponent({ inlineAttrs })
- const input = container.querySelector('input')
- const checkbox = getByText('checkbox')
+ renderComponent({ inlineAttrs })
+ const input = screen.getByLabelText('check') // input
+ const checkbox = screen.getByText('check') // div with text
expect(input).toBeDisabled()
@@ -71,9 +71,9 @@ test('Uncontrolled - should not check if disabled', async () => {
})
test('Uncontrolled - should check and uncheck', async () => {
- const { container, getByText } = renderComponent()
- const input = container.querySelector('input')
- const checkbox = getByText('checkbox')
+ renderComponent()
+ const input = screen.getByLabelText('check') // input
+ const checkbox = screen.getByText('check') // div with text
// click the first time, it's checked
await userEvent.click(checkbox)
@@ -85,23 +85,21 @@ test('Uncontrolled - should check and uncheck', async () => {
})
test('properly handles v-model', async () => {
- const { getByText, container } = renderComponent(
- {
- data: () => ({
- enable: false
- }),
- template: `
+ renderComponent({
+ data: () => ({
+ enable: false
+ }),
+ template: `
{{enable ? 'enabled' : 'disabled'}}
-
+ check
`
- }
- )
- const input = container.querySelector('input')
+ })
+ const input = screen.getByLabelText('check') // input
- expect(getByText('disabled')).toBeInTheDocument()
+ expect(screen.getByText('disabled')).toBeInTheDocument()
await userEvent.click(input)
- expect(getByText('enabled')).toBeInTheDocument()
+ expect(screen.getByText('enabled')).toBeInTheDocument()
})
diff --git a/packages/chakra-ui-core/src/CCheckbox/tests/__snapshots__/CCheckbox.test.js.snap b/packages/chakra-ui-core/src/CCheckbox/tests/__snapshots__/CCheckbox.test.js.snap
index 92141cec..3f97af56 100644
--- a/packages/chakra-ui-core/src/CCheckbox/tests/__snapshots__/CCheckbox.test.js.snap
+++ b/packages/chakra-ui-core/src/CCheckbox/tests/__snapshots__/CCheckbox.test.js.snap
@@ -46,7 +46,7 @@ exports[`should render correctly 1`] = `
class="css-np4rym"
data-chakra-component="CBox"
>
- checkbox
+ check
diff --git a/packages/chakra-ui-core/src/CCheckboxGroup/tests/CCheckboxGroup.test.js b/packages/chakra-ui-core/src/CCheckboxGroup/tests/CCheckboxGroup.test.js
index 522f3f16..71549b95 100644
--- a/packages/chakra-ui-core/src/CCheckboxGroup/tests/CCheckboxGroup.test.js
+++ b/packages/chakra-ui-core/src/CCheckboxGroup/tests/CCheckboxGroup.test.js
@@ -1,5 +1,5 @@
import { CBox, CCheckbox, CCheckboxGroup } from '../..'
-import { render } from '@/tests/test-utils'
+import { render, screen, wait } from '@/tests/test-utils'
// mocks
import { useId } from '@/packages/chakra-ui-core/src/utils'
@@ -33,20 +33,18 @@ it('should render correctly', () => {
})
it('should display children', () => {
- const { getByText } = renderComponent()
- expect(getByText('One')).toBeInTheDocument()
- expect(getByText('Two')).toBeInTheDocument()
- expect(getByText('Three')).toBeInTheDocument()
+ renderComponent()
+ expect(screen.getByText('One')).toBeInTheDocument()
+ expect(screen.getByText('Two')).toBeInTheDocument()
+ expect(screen.getByText('Three')).toBeInTheDocument()
})
test('selectedValues prop works', () => {
- const { getByTestId } = renderComponent()
+ renderComponent()
- const one = getByTestId('one').querySelector('input')
- const two = getByTestId('two').querySelector('input')
- const three = getByTestId('three').querySelector('input')
-
- expect(one).not.toBeChecked()
- expect(two).toBeChecked()
- expect(three).not.toBeChecked()
+ wait(() => {
+ expect(screen.getByLabelText('One')).not.toBeChecked()
+ expect(screen.getByLabelText('Two')).toBeChecked()
+ expect(screen.getByLabelText('Three')).not.toBeChecked()
+ })
})
diff --git a/packages/chakra-ui-core/src/CCircularProgress/tests/CCircularProgress.test.js b/packages/chakra-ui-core/src/CCircularProgress/tests/CCircularProgress.test.js
index f8007f41..280c0c3c 100644
--- a/packages/chakra-ui-core/src/CCircularProgress/tests/CCircularProgress.test.js
+++ b/packages/chakra-ui-core/src/CCircularProgress/tests/CCircularProgress.test.js
@@ -1,5 +1,5 @@
import { CCircularProgress, CCircularProgressLabel } from '../..'
-import { render } from '@/tests/test-utils'
+import { render, screen } from '@/tests/test-utils'
const renderComponent = (props) => {
const base = {
@@ -20,26 +20,26 @@ it('should render correctly', () => {
})
it('should display a label', () => {
- const { queryByText } = renderComponent({
+ renderComponent({
template: `