question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to write tests for useTransition with v9 api?

See original GitHub issue

🤓 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();
    });

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
m98commented, Apr 4, 2021

@aleclarson using Globals.assign({ skipAnimation: true }) in a .test.tsx file gives me the following error (I’m using version 9.0.0-rc.3):

TypeError: Cannot read property 'assign' of undefined

2reactions
aleclarsoncommented, Jun 9, 2020

Have you tried the skipAnimation global?

import { Globals } from 'react-spring'

Globals.assign({ skipAnimation: true })

I’ve tried using react-spring/mock-raf but tests will hang with it.

We use that lib for internal tests, and it works as expected, so you’re likely misusing it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write tests for useTransition with v9 api? #1048 - GitHub
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.
Read more >
useTransition - react-spring
useTransition. This hook is best suited for animating in & out datasets or items you don't particularly want to be left in the...
Read more >
Unit Testing Controllers in ASP.NET Web API 2 - Microsoft Learn
A common pattern in unit tests is "arrange-act-assert": Arrange: Set up any prerequisites for the test to run. Act: Perform the test. Assert: ......
Read more >
All You Need to Know About React Spring Jammed Into 1 Article
In this tutorial, we walk you through using React Spring library to provide awesome animations to your CRA (React App) and enhance your...
Read more >
Animation transitions and triggers - Angular
This guide goes into depth on special transition states such as the * wildcard and void . It shows how these special states...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found