From 0e2b53b740a5ed852521705ccfe0e1d83e9aab23 Mon Sep 17 00:00:00 2001 From: Josh Black Date: Wed, 7 Jul 2021 08:25:07 -0500 Subject: [PATCH] fix(react): update radio button group state initialization (#9104) * fix(react): update radio button group state initialization * test(react): add test for RadioButtonGroup * feat(jest-config): add jest-dom as default matcher Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../jest-config-carbon/setup/setupAfterEnv.js | 2 + .../Accordion/__tests__/Accordion-test.js | 1 - .../src/components/Button/Button-test.js | 1 - .../src/components/Checkbox/Checkbox-test.js | 1 - .../react/src/components/Link/Link-test.js | 1 - .../Notification/next/Notification-test.js | 1 - .../RadioButtonGroup/RadioButtonGroup-test.js | 301 +++++++++++------- .../RadioButtonGroup/RadioButtonGroup.js | 14 +- .../components/TabContent/TabContent-test.js | 1 - 9 files changed, 197 insertions(+), 126 deletions(-) diff --git a/config/jest-config-carbon/setup/setupAfterEnv.js b/config/jest-config-carbon/setup/setupAfterEnv.js index ee334a8f3814..748b6a4e2305 100644 --- a/config/jest-config-carbon/setup/setupAfterEnv.js +++ b/config/jest-config-carbon/setup/setupAfterEnv.js @@ -10,6 +10,8 @@ const util = require('util'); const toHaveNoAxeViolations = require('../matchers/toHaveNoAxeViolations'); const toHaveNoACViolations = require('../matchers/toHaveNoACViolations'); +require('@testing-library/jest-dom'); + // We can extend `expect` using custom matchers as defined by: // https://jest-bot.github.io/jest/docs/expect.html#expectextendmatchers // diff --git a/packages/react/src/components/Accordion/__tests__/Accordion-test.js b/packages/react/src/components/Accordion/__tests__/Accordion-test.js index df2f4a2d02b5..58db60bc2eea 100644 --- a/packages/react/src/components/Accordion/__tests__/Accordion-test.js +++ b/packages/react/src/components/Accordion/__tests__/Accordion-test.js @@ -9,7 +9,6 @@ import React from 'react'; import { default as Accordion, AccordionItem } from '../'; import { cleanup, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import '@testing-library/jest-dom'; describe('Accordion', () => { afterEach(cleanup); diff --git a/packages/react/src/components/Button/Button-test.js b/packages/react/src/components/Button/Button-test.js index cc17b1e7bbe3..d073f9c0b5f0 100644 --- a/packages/react/src/components/Button/Button-test.js +++ b/packages/react/src/components/Button/Button-test.js @@ -14,7 +14,6 @@ import { shallow, mount } from 'enzyme'; import { settings } from 'carbon-components'; import { cleanup, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import '@testing-library/jest-dom'; const { prefix } = settings; diff --git a/packages/react/src/components/Checkbox/Checkbox-test.js b/packages/react/src/components/Checkbox/Checkbox-test.js index 207ac66339d0..e4cb628aecf3 100644 --- a/packages/react/src/components/Checkbox/Checkbox-test.js +++ b/packages/react/src/components/Checkbox/Checkbox-test.js @@ -12,7 +12,6 @@ import { mount } from 'enzyme'; import { settings } from 'carbon-components'; import { cleanup, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import '@testing-library/jest-dom'; const { prefix } = settings; diff --git a/packages/react/src/components/Link/Link-test.js b/packages/react/src/components/Link/Link-test.js index 173ad112da4e..f78f5bb7c892 100644 --- a/packages/react/src/components/Link/Link-test.js +++ b/packages/react/src/components/Link/Link-test.js @@ -10,7 +10,6 @@ import Link from '../Link'; import { shallow } from 'enzyme'; import { settings } from 'carbon-components'; import { cleanup, render, screen } from '@testing-library/react'; -import '@testing-library/jest-dom'; import userEvent from '@testing-library/user-event'; import { describe, document } from 'window-or-global'; diff --git a/packages/react/src/components/Notification/next/Notification-test.js b/packages/react/src/components/Notification/next/Notification-test.js index 263cf7873b69..5ecbecdd59dd 100644 --- a/packages/react/src/components/Notification/next/Notification-test.js +++ b/packages/react/src/components/Notification/next/Notification-test.js @@ -15,7 +15,6 @@ import { } from '../next/Notification'; import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import '@testing-library/jest-dom'; import { settings } from 'carbon-components'; import { it } from 'window-or-global'; diff --git a/packages/react/src/components/RadioButtonGroup/RadioButtonGroup-test.js b/packages/react/src/components/RadioButtonGroup/RadioButtonGroup-test.js index d3a1f8047c49..44a3720afd81 100644 --- a/packages/react/src/components/RadioButtonGroup/RadioButtonGroup-test.js +++ b/packages/react/src/components/RadioButtonGroup/RadioButtonGroup-test.js @@ -5,155 +5,222 @@ * LICENSE file in the root directory of this source tree. */ +import { render, screen } from '@testing-library/react'; import React from 'react'; import { shallow, mount } from 'enzyme'; import RadioButtonGroup from '../RadioButtonGroup'; import RadioButton from '../RadioButton'; -import { settings } from 'carbon-components'; - -const { prefix } = settings; describe('RadioButtonGroup', () => { - describe('renders as expected', () => { - const wrapper = mount( - - - + it('should render `legendText` in a