title: Functions in a jest test only work when launched alone, but not at the same time
body: <p>I have a custom hook that updates a state. The state is made with immer thanks to useImmer().</p>
  <p>I have written the tests with Jest &amp; &quot;testing-library&quot; - which allows to test hooks -.</p>
  <p>All the functions work when launched alone. But when I launch them all in the same time, only the first one succeed. How so?</p>
  <p>Here is the hook: (simplified for the sake of clarity):</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export default function useSettingsModaleEditor(draftPage) {
    const [settings, setSettings] = useImmer(draftPage);
    
    const enablePeriodSelector = (enable: boolean) =&gt; {
      return setSettings((draftSettings) =&gt; {
        draftSettings.periodSelector = enable;
      });
    };
  
    const enableDynamicFilter = (enable: boolean) =&gt; {
      return setSettings((draftSettings) =&gt; {
        draftSettings.filters.dynamic = enable;
      });
    };
  
    const resetState = () =&gt; {
      return setSettings((draftSettings) =&gt; {
        draftSettings.filters.dynamic = draftPage.filters.dynamic;
        draftSettings.periodSelector = draftPage.periodSelector;
        draftSettings.filters.static = draftPage.filters.static;
      });
    };
  
    return {
      settings,
      enablePeriodSelector,
      enableDynamicFilter,
      resetState,
    };
  }</code></pre>
  </div>
  </div>
  </p>
  <p>And the test:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>describe("enablePeriodSelector", () =&gt; {
    const { result } = useHook(() =&gt; useSettingsModaleEditor(page));
    it("switches period selector", () =&gt; {
      act(() =&gt; result.current.enablePeriodSelector(true));
      expect(result.current.settings.periodSelector).toBeTruthy();
      act(() =&gt; result.current.enablePeriodSelector(false));
      expect(result.current.settings.periodSelector).toBeFalsy();
    });
  });
  
  describe("enableDynamicFilter", () =&gt; {
    const { result } = useHook(() =&gt; useSettingsModaleEditor(page));
    it("switches dynamic filter selector", () =&gt; {
      act(() =&gt; result.current.enableDynamicFilter(true));
      expect(result.current.settings.filters.dynamic).toBeTruthy();
      act(() =&gt; result.current.enableDynamicFilter(false));
      expect(result.current.settings.filters.dynamic).toBeFalsy();
    });
  });
  
  describe("resetState", () =&gt; {
    const { result } = useHook(() =&gt; useSettingsModaleEditor(page));
    it("switches dynamic filter selector", () =&gt; {
      act(() =&gt; result.current.enableDynamicFilter(true));
      act(() =&gt; result.current.enablePeriodSelector(true));
      act(() =&gt; result.current.addShortcut(Facet.Focuses));
      act(() =&gt; result.current.resetState());
      expect(result.current.settings.periodSelector).toBeFalsy();
      expect(result.current.settings.filters.dynamic).toBeFalsy();
      expect(result.current.settings.filters.static).toEqual([]);
    });
  });</code></pre>
  </div>
  </div>
  </p>
  <p>All functions works in real life. How to fix this? Thanks!</p>