Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Feature/33 add unit tests #50

Merged
merged 18 commits into from
Feb 21, 2022
Merged

Feature/33 add unit tests #50

merged 18 commits into from
Feb 21, 2022

Conversation

halsk
Copy link
Member

@halsk halsk commented Feb 20, 2022

Add a unit test for EditableProperty.tsx

But it is not the expected result.

Below error was fixed by 565df4e

yarn test:ci shows errors

yarn run v1.22.17
$ jest --coverage
 PASS  __test__/atoms/button/PrimaryButton.test.tsx
 PASS  __test__/molecules/forms/EditableProperty.test.tsx
  ● Console

    console.log


      at canceled (src/components/molecules/forms/EditableProperty.tsx:58:13)
          at Array.some (<anonymous>)

    console.error
      Warning: An update to foo inside a test was not wrapped in act(...).
      
      When testing, code that causes React state updates should be wrapped into act(...):
      
      act(() => {
        /* fire events that update state */
      });
      /* assert on the output */
      
      This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
          at foo (/Users/hal/Documents/workspace/supabase-test/src/components/molecules/forms/EditableProperty.tsx:53:11)
          at WrapperComponent (/Users/hal/Documents/workspace/supabase-test/node_modules/@wojtekmaj/enzyme-adapter-utils/src/createMountWrapper.jsx:46:26)

      65 |       .then()
      66 |       .catch((error) => {
    > 67 |         setErrorMessage(error.message);
         |         ^
      68 |       });
      69 |   }
      70 |   useEffect(() => { 

      at printWarning (node_modules/react-dom/cjs/react-dom.development.js:67:30)
      at error (node_modules/react-dom/cjs/react-dom.development.js:43:5)
      at warnIfNotCurrentlyActingUpdatesInDEV (node_modules/react-dom/cjs/react-dom.development.js:24064:9)
      at setErrorMessage (node_modules/react-dom/cjs/react-dom.development.js:16135:9)
      at src/components/molecules/forms/EditableProperty.tsx:67:9

I couldn't find a good way for rendering error text

I wanted to wait for rendering of setErrorMessage() of EditableProperty.tsx:67, but I can't find a good way to do it.
Using setTimeout solved it but it is not the ideal way.

__test__/molecules/forms/EditableProperty.test.tsx:107

    /* blow test is failed
        expect(app.find('Text.errors').text()).toEqual('error text');
     */
    await function () {
      setTimeout(() => {
        expect(app.find('Text.errors').text()).toEqual('error text');
      }, 100);
    };

@halsk halsk merged commit 36a1083 into main Feb 21, 2022
@halsk halsk deleted the feature/33-add-unit-tests branch February 21, 2022 12:59
@MaySoMusician MaySoMusician linked an issue Feb 22, 2022 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create tests for existing features
1 participant