Skip to content

Commit

Permalink
Resolve some warning message during test (#1895)
Browse files Browse the repository at this point in the history
<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] I tested the changes in various browsers. (or didn't have to)
  - Windows: Chrome, Edge, (Optional) Firefox
  - macOS: Chrome, Edge, Safari, (Optional) Firefox

## Related Issue
<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

- #1877 

## Summary
<!-- Please brief explanation of the changes made -->

- `yarn test`실행 시 테스트 코드에서 나오는 warning message의 일부를 resolve합니다.
-
https://app.circleci.com/pipelines/github/channel-io/bezier-react/5804/workflows/c0aae4cd-38de-4423-a3fc-9480443ef7f9/jobs/22311
여기서 실행 결과를 보면, 성공한 테스트임에도 불구하고 굉장히 많은 경고 메시지가 테스트 결과에 포함되는 것을 볼 수 있습니다.
이런 불필요한 메시지가 로그에 포함되면 테스트 코드 결과를 파악하기도 어렵고, 경고 메시지 자체가 잠재적인 버그의 원인이기 때문에
결코 무시할 수 없습니다.
- 이번 작업으로 95%이상 경고 메시지를 줄였고, scss 마이그레이션 작업을 하면서 완전히 없애면 좋을 것 같습니다

## Details
<!-- Please elaborate description of the changes -->

- 에러 메시지의 원인은 아래와 같았습니다.
- jest test callback 함수 안에서 비동기 작업이 수행됨 -> 대부분의 로그를 차지하고 있는 문제로,
FeatureProvider 안에서 오타 수정하면 Promise 실행 안하게 됨

![image](https://github.com/channel-io/bezier-react/assets/28595102/7718e398-1669-40b2-8401-10df7fe2f45a)

- active="false" -> 정확한 원인은 아직 파악 안된 상태..

![image](https://github.com/channel-io/bezier-react/assets/28595102/661261e1-2ee9-45ea-a596-dc6f5c9a00be)

- Icon컴포넌트의 forwardRef -> 아마 styled(Icon) 으로 감싸고 나서 asChild로 인한 ref
forwarding이 안되는 이슈인 듯하여 scss로 마이그레이션 하면 해결 됫 것으로 예상

![image](https://github.com/channel-io/bezier-react/assets/28595102/44a06aec-2d2b-4f50-a4c3-bababb949cb7)

- ref forwarding 이 누락됨

![image](https://github.com/channel-io/bezier-react/assets/28595102/be545eee-ea39-4bd7-9d24-fcedcb5c3c95)

- hasError 속성을 잘못 넘김
(#1876 참고)

![image](https://github.com/channel-io/bezier-react/assets/28595102/7dffef91-da80-450d-bdcc-b2ed0dd0824f)


### Breaking change? (Yes/No)
<!-- If Yes, please describe the impact and migration path for users -->
- No

## References
<!-- Please list any other resources or points the reviewer should be
aware of -->

-
https://davidwcai.medium.com/react-testing-library-and-the-not-wrapped-in-act-errors-491a5629193b
  • Loading branch information
yangwooseong authored Jan 11, 2024
1 parent 66923cc commit 3f781aa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function RadioGroupImpl<Value extends string>({
direction = 'vertical',
...rest
}: RadioGroupProps<Value>, forwardedRef: React.Ref<HTMLDivElement>) {
const formFieldProps = useFormFieldProps(rest)
const { hasError, ...formFieldProps } = useFormFieldProps(rest)

return (
<RadioGroupPrimitive.Root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {
type ForwardedRef,
forwardRef,
useEffect,
useMemo,
Expand Down Expand Up @@ -63,7 +64,7 @@ function SegmentedControlItemListImpl<
style,
className,
...rest
}: SegmentedControlItemListProps<Type, Value>) {
}: SegmentedControlItemListProps<Type, Value>, forwardedRef: ForwardedRef<HTMLDivElement>) {
const [selectedItemIndex, setSelectedItemIndex] = useState<number | null>(null)

const {
Expand All @@ -83,6 +84,7 @@ function SegmentedControlItemListImpl<
return (
<SegmentedControlItemList
asChild
ref={forwardedRef}
{...rest}
>
<HStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const Switch = forwardRef<HTMLButtonElement, SwitchProps>(function Switch
const {
disabled,
required,
hasError,
...ownProps
} = useFormFieldProps(rest)

Expand Down
3 changes: 2 additions & 1 deletion packages/bezier-react/src/features/FeatureProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {
} from 'react'

import { createContext } from '~/src/utils/react'
import { isEmpty } from '~/src/utils/type'

import {
type Feature,
Expand Down Expand Up @@ -48,7 +49,7 @@ export function FeatureProvider({
const [featureFlag, setFeatureFlag] = useState<FeatureFlag>(initialFeatureFlag)

useLayoutEffect(function activateFeatures() {
if (!features) {
if (isEmpty(features)) {
return
}

Expand Down

0 comments on commit 3f781aa

Please sign in to comment.