Browse Source

test(js): Refactor useLegacyStore test to use testing-library/react-hooks (#29338)

Evan Purkhiser 3 years ago
parent
commit
e765f3c1a4
1 changed files with 6 additions and 12 deletions
  1. 6 12
      tests/js/spec/stores/useLegacyStore.spec.tsx

+ 6 - 12
tests/js/spec/stores/useLegacyStore.spec.tsx

@@ -1,4 +1,4 @@
-import {act, mountWithTheme} from 'sentry-test/reactTestingLibrary';
+import {act, renderHook} from '@testing-library/react-hooks';
 
 import TeamStore from 'app/stores/teamStore';
 import {useLegacyStore} from 'app/stores/useLegacyStore';
@@ -7,21 +7,15 @@ describe('useLegacyStore', () => {
   // @ts-expect-error
   const team = TestStubs.Team();
 
-  function TestComponent() {
-    const teamStore = useLegacyStore(TeamStore);
-    return <div>Teams: {teamStore.teams.length}</div>;
-  }
-
-  afterEach(() => {
-    TeamStore.reset();
-  });
+  beforeEach(() => void TeamStore.reset());
 
   it('should update on change to store', () => {
-    const wrapper = mountWithTheme(<TestComponent />);
-    expect(wrapper.getByText('Teams: 0')).toBeTruthy();
+    const {result} = renderHook(() => useLegacyStore(TeamStore));
+
+    expect(result.current.teams).toEqual([]);
 
     act(() => TeamStore.loadInitialData([team]));
 
-    expect(wrapper.getByText('Teams: 1')).toBeTruthy();
+    expect(result.current.teams).toEqual([team]);
   });
 });