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.

Advice on mocking animations

See original GitHub issue

Hello, first off, thanks for an awesome component!

We’re trying to create a snapshot test using Jest for a component that uses react-native-modal. Upon running, it errors on initializeRegistryWithDefinitions.

nomock

We then tried mocking it with

import { View } from 'react-native';

const initializeRegistryWithDefinitions = jest.fn();
export {
  View,
  initializeRegistryWithDefinitions
};

which gave another error. image

Any advice on what is the correct way to mock this? Ultimately I know we have to mock react-native-animatable which I already am doing above without initializeRegistryWithDefinitions 😃

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
dcarrot2commented, May 15, 2017

No worries, thanks for getting back to me!

Out of curiosity, why do you never test UI components?

So I tried mocking transitionTo without any luck. I think why it didn’t work is because modal utilizes React’s ref which react-test-renderer per here doesn’t support unless it is explicitly mocked out via createNodeMock but I guess it only does it for the component being tested and not any dependent components down the tree? (In this case, <MyComponent /> -> <Modal /> -> <Animatable’s Wrapped View />).

I was able to workaround by completely stubbing out via jest in my test.

import React from 'react';
import renderer from 'react-test-renderer';
import ItemFetchModal from '../../../app/components/inventory/item-fetch-modal';

jest.mock('react-native-modal', () => 'react-native-modal');

it('renders correctly', () => {
  const tree = renderer.create(<ItemFetchModal />).toJSON();
  expect(tree).toMatchSnapshot();
});

Thanks again for the response! 😄

0reactions
acaillycommented, Apr 2, 2021

I fixed this issue today for my specific usecase and without mocking all of react-native-modal, maybe that could help: https://github.com/oblador/react-native-animatable/issues/97#issuecomment-812448746

Read more comments on GitHub >

github_iconTop Results From Across the Web

Animating your mock-ups with the timeline - Rotato
How to animate your device mockup (video) · Working with keyframes. Duration; Easing; Change mockup angle for a keyframe; Delete a keyframe; Delete...
Read more >
[User Guide] Character Rigging and Mock up Animations
Details and Download : https://videohive.net/item/character-rigging- mock -up- animations /30582147.
Read more >
4 techniques for creating mockups to show off your designs
This article describes how to make mockups that look professional using 4 different techniques. We break them down for you and include all...
Read more >
Getting GIFy with it: How to mock up background video in Figma
The new solution: Drop an animated GIF into Figma. If you drop an animated GIF into Figma, it will automatically play in presentation...
Read more >
How to create animated photo-realistic mockups with Photoshop
Here, you'll see the video in situ of the mock. Photoshop realistic mockup video save layer to master. Step 6: Adjust the timings....
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