How to use the @testing-library/react.act function in @testing-library/react

To help you get started, we’ve selected a few @testing-library/react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / @testing-library / react_v8.x.x / flow_v0.104.x- / test_react_v8.x.x.js View on Github external
it('should fail on incorrect usage of result', () => {
    // $ExpectError
    act(() => {}) + 1;
    // $ExpectError
    act(() => {}).doesNotExist();
    // $ExpectError
    act(() => {}).then(1);
    // $ExpectError
    act(() => {}).then(() => {}, 1);
  });
github schiehll / react-alert / __tests__ / react-alert.spec.js View on Github external
it('should remove an alert on close click', () => {
      fireEvent.click(getByText(/show alert/i))
      const alertElement = getByText(/message/i)
      expect(getByText(/message/i)).toBeInTheDocument()

      fireEvent.click(getByText(/close/i))

      act(jest.runAllTimers)

      expect(alertElement).not.toBeInTheDocument()
    })
github flow-typed / flow-typed / definitions / npm / @testing-library / react_v8.x.x / flow_v0.104.x- / test_react_v8.x.x.js View on Github external
it('should pass on correct usage of result', () => {
    act(() => {}).then(() => {});
    act(() => {}).then(() => {}, () => {});
  });
});
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / Notifications / __tests__ / stickyFullScreen.tsx View on Github external
function pushStickyNotification() {
  act(() =>
    getNotificationsMethods().pushStickyNotification({
      id: 'build',
      type: 'loading',
      title: 'Rebuilding...',
      info: 'Your code is updating.'
    })
  );
}
github reduxjs / react-redux / test / hooks / useSelector.spec.js View on Github external
)

        expect(renderedItems).toEqual([0])

        rtl.act(forceRender)
        expect(renderedItems).toEqual([0, 1])

        rtl.act(() => {
          store.dispatch({ type: '' })
        })
        expect(renderedItems).toEqual([0, 1])

        rtl.act(forceRender)
        expect(renderedItems).toEqual([0, 1, 2])
      })
github schiehll / react-alert / __tests__ / react-alert.spec.js View on Github external
)

      const { getByText } = render()
      fireEvent.click(getByText(/show alert 0/i))
      fireEvent.click(getByText(/show alert 1/i))

      const alert0Element = getByText(/message 0/i)
      expect(getByText(/message 0/i)).toBeInTheDocument()

      const alert1Element = getByText(/message 1/i)
      expect(getByText(/message 1/i)).toBeInTheDocument()

      fireEvent.click(getByText(/remove all alerts/i))
      act(jest.runOnlyPendingTimers)

      expect(alert0Element).not.toBeInTheDocument()
      expect(alert1Element).not.toBeInTheDocument()
    })
github Satyam / react-simple-idle-monitor / __tests__ / setup.ts View on Github external
export function advanceTimers(ms): void {
  now += ms;
  Date.now = (): number => now;
  act((): void => {
    jest.advanceTimersByTime(ms);
  });
}
github atlassian / react-beautiful-dnd / test / unit / integration / drag-handle / shared-behaviours / abort-on-error.spec.js View on Github external
function execute() {
    act(() => {
      invariant(current, 'Expected throw callback to be set');
      current();
    });
  }
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / Notifications / __tests__ / stickyMultiple.tsx View on Github external
function pushStickyNotifications() {
  const { pushStickyNotification } = getNotificationsMethods();
  act(() => {
    pushStickyNotification({
      id: 'one',
      type: 'info',
      title: 'Check this out',
      info: 'Lorem ipsum.'
    });
    pushStickyNotification({
      id: 'two',
      type: 'info',
      title: 'Take a look at this',
      info: 'Lorem ipsum.'
    });
  });
}
github alloc / wana / spec / .setup.ts View on Github external
  render(depth, () => act(effect))
}