Skip to content

Component not rendering in Mocha #96

Closed
@CodingItWrong

Description

@CodingItWrong

I'm attempting to create a "Hello World" component to try out RNTL with Mocha and I'm getting an error attempting to render the component.

Full reproduction repo: https://github.com/CodingItWrong/RNTLTestMocha

Component:

import React from 'react';
import { View, Text } from 'react-native';

export default function Hello() {
  return <View>
    <Text>asdf</Text>
  </View>;
}

Test:

import { expect } from 'chai';
import React from 'react';
import { render, fireEvent } from 'react-native-testing-library';

import Hello from '../Hello';

describe('Hello', () => {
  it('displays the message', () => {
    const { debug, getByText } = render(<Hello />);

    debug();

    expect(getByText('asdf')).not.to.be.null;
  });
});

Error:

  1) Hello
       displays the message:
     Error: Cannot find module 'View'
      at require (internal/module.js:11:18)
      at Object.get View [as View] (node_modules/react-native/Libraries/react-native/react-native-implementation.js:167:12)
      at Hello (Hello.js:5:11)
      at mountIndeterminateComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6889:13)

I have react-test-renderer installed. Does RNTL work with Mocha? Am I missing another dependency? If it's Jest-only I think it would be good to add a note in the README; I can PR that if so.

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