Skip to content

How to write tests for useTransition with v9 api? #1048

@fernandofleury

Description

@fernandofleury

🤓 Question

(I did search around stackoverflow and spectrum)

How to properly test useTransition using v9 api? I've tried using https://github.com/react-spring/mock-raf but tests will hang with it. Also tried mocking raf to a regular:

const FPS = 16;
global.requestAnimationFrame = (callback) => {
  setTimeout(callback, FPS);
};

Testing items being added seems to work as expected, but I can't get to properly test item removal, for example:

    it('should remove a notification on click', async () => {
      const { queryByTestId } = renderComponent();

      fireEvent.click(queryByTestId('button-selector');

      expect(queryByTestId('notification-selector')).toBeTruthy();

      jest.advanceTimersByTime(NOTIFICATION_TIMER);

      expect(queryByTestId('notification-selector')).toBeNull();
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions