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.

fails with typescript and react-test-renderer

See original GitHub issue
    TypeError: Cannot read property 'Constants' of undefined

      at Video.render (node_modules/react-native-video/Video.js:210:59)
      at finishClassComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5276:31)
      at updateClassComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5238:10)
      at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5907:14)
      at performUnitOfWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7949:12)
      at workLoop (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7980:24)
      at renderRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8020:7)
      at performWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8592:22)
      at performWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8527:7)
      at performSyncWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:8499:3)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
ethanneffcommented, Dec 21, 2018

I never solved it. I just mocked the entire react-native-video dependency with a string so I could build a snapshot off the component with a Video inside it.

import React from "react";
import renderer from "react-test-renderer";
import Component from "..";

jest.mock("react-native-video", () => "Video");

describe("Video Component", () => {
  const video = require("../../../commons/Assets/Exercises/Back/intro.mp4");
  it("renders correctly", () => {
    const component = renderer.create(<Component source={video} />).toJSON();
    expect(component).toMatchSnapshot();
  });
});
0reactions
genkobarcommented, Jan 21, 2019

@ethanneff Did you only encounter this when doing snapshot tests, or also when you were running the app proper?

I ask because the Jest documentation notes that when doing snapshot tests of anything that makes use of native code, you need to mock it (like you’ve done here) because Jest can’t run native code.

However some react-native components or third party components rely on native code to be rendered. In such cases, Jest’s manual mocking system can help to mock out the underlying implementation. #

Well, it doesn’t state it directly, but this is the only part of the documentation that talks about components that rely on native code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript error for React test Renderer JSON not having ...
I have created an expo app with the basic typescript template as documented. Installed all the requirements needed for testing and ...
Read more >
fails with typescript and react-test-renderer #1208 - GitHub
I just mocked the entire react-native-video dependency with a string so I could build a snapshot off the component with a Video inside...
Read more >
Test Renderer - React
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM...
Read more >
Why is my jest test failing in React native with typescript?
[Solved]-Why is my jest test failing in React native with typescript?-Reactjs ... The error was related a missing jest configuration in the package.json....
Read more >
Setup - Testing Library
Javascript; Typescript. my-component.test.jsx. - import { render, fireEvent } from '@testing-library/react'; + import { render, fireEvent } ...
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