Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactNative Animated is not properly mocked #4359

Closed
sospedra opened this issue Aug 25, 2017 · 11 comments
Closed

ReactNative Animated is not properly mocked #4359

sospedra opened this issue Aug 25, 2017 · 11 comments

Comments

@sospedra
Copy link

sospedra commented Aug 25, 2017

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Animated is not mocked

Using
react-native 0.47
jest 20
react 16
react-test-renderer 16

Implement any Animated component. With the new Animated.value and so on. And make a snapshot test.

It'll return:

Log error
 const wrapper = this._environment.runScript(transformedFile.script)[
                                                                     ^

TypeError: Cannot read property 'Object.<anonymous>' of null
  at Runtime._execModule (/Users/rigel/labs/mobile-apps/node_modules/jest-runtime/build/index.js:510:72)
  at Runtime.requireModule (/Users/rigel/labs/mobile-apps/node_modules/jest-runtime/build/index.js:329:14)
  at Runtime.requireModuleOrMock (/Users/rigel/labs/mobile-apps/node_modules/jest-runtime/build/index.js:405:19)
  at Function.bezier (/Users/rigel/labs/mobile-apps/node_modules/react-native/Libraries/Animated/src/Easing.js:228:13)
  at ease (/Users/rigel/labs/mobile-apps/node_modules/react-native/Libraries/Animated/src/Easing.js:94:14)
  at TimingAnimation._easing (/Users/rigel/labs/mobile-apps/node_modules/react-native/Libraries/Animated/src/Easing.js:262:10)
  at TimingAnimation.onUpdate (/Users/rigel/labs/mobile-apps/node_modules/react-native/Libraries/Animated/src/AnimatedImplementation.js:338:22)
  at ontimeout (timers.js:365:14)
  at tryOnTimeout (timers.js:237:5)
  at Timer.listOnTimeout (timers.js:207:5)

What is the expected behavior?

Should mock properly Animated, like the other react-native components so it doesn't break.

@sospedra sospedra changed the title Animated is not properly mocked ReactNative Animated is not properly mocked Aug 25, 2017
@cpojer
Copy link
Member

cpojer commented Aug 25, 2017

This is not a Jest issue, this is an issue with react-native.

Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions. Thank you :)

@cpojer cpojer closed this as completed Aug 25, 2017
@sospedra
Copy link
Author

sospedra commented Aug 28, 2017

It looks like a jest bug to me. A bug related with timers.
See this thread: #2979 (comment)

@AtticusFetch
Copy link

@sospedra , I am having the same issue, were you able to find a workaround?

@sospedra
Copy link
Author

@AtticusFetch For reasons we needed the timer to be fixed hence we started using jest.useFakeTimers() and Date.now = jest.fn(() => 1503187200000). This causes jest to stop using timer worker-farm thus avoiding the error.

Hope it helps

@salujaharkirat
Copy link

This works fine. However adding this breaks promise based this cases

@duranmla
Copy link

duranmla commented Aug 15, 2018

I think this is the same that @sospedra wanted to let us know but I will just mention that by only adding:

jest.useFakeTimers();

On the top of your test file, it will make it work, I haven't dug too much into how/why it works, but it does it. Cheers.

Reference at:

PD: it seems to affect only the single file where you add the code so I do not see any bad consequence on adding it

tricoder42 added a commit to lingui/js-lingui that referenced this issue Sep 6, 2018
@shushanth
Copy link

Was having the similar issue with RN 59,

use the below things to get rid of this error ,

  • Remove import 'jsdom-global/register'; from tests .

  • "testEnvironment": "jsdom" and "timers": "fake", should be used in jest configuration.

    "jest": {
    ...........
    "timers": "fake",
    "testEnvironment": "jsdom"
    ............
    }

@Gp2mv3
Copy link

Gp2mv3 commented Jul 3, 2019

This did it for me:

 "testEnvironment": "jsdom"

Photonios pushed a commit to SectorLabs/js-lingui that referenced this issue Dec 9, 2019
@RageOfJustice
Copy link

Was having the similar issue with RN 59,

use the below things to get rid of this error ,

  • Remove import 'jsdom-global/register'; from tests .
  • "testEnvironment": "jsdom" and "timers": "fake", should be used in jest configuration.
    "jest": {
    ...........
    "timers": "fake",
    "testEnvironment": "jsdom"
    ............
    }

Thanks. It helped me with FlatList snapshot

@allanyego
Copy link

@duranmla , thanks for that trick. I was having issues in CodeSandbox even after explicitly setting test environment to node.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants