Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

displayName for components not set during testing #421

Open
demeralde opened this issue Oct 12, 2018 · 0 comments
Open

displayName for components not set during testing #421

demeralde opened this issue Oct 12, 2018 · 0 comments

Comments

@demeralde
Copy link

Is this a bug report?

Yes.

Environment

  1. react-scripts-ts version: [email protected]
  2. node -v: v8.10.0
  3. npm -v: 6.4.1
  4. yarn --version: 1.10.1
  5. enzyme version: 3.7.0
  6. enzyme-adapter-react-16 version: ^1.6.0

Operating system: Ubuntu 18.04.1

Steps to Reproduce

  1. Create a functional React component:
import React from 'react';

export const TestComponent = () => (
  <div>
    test
  </div>
);
  1. Create a test for the component:
console.log(component.debug());
console.log(TestComponent.displayName);
expect(component.find('TestComponent')).toHaveLength(1);

Expected Behavior

Enzyme should be able to find the component using its displayName (TestComponent).

Actual Behavior

Enzyme can't find the component because it doesn't have a displayName. The output of debug() prints <Component /> instead of the component's actual name.

Other notes

This works fine during development; if I inspect my React tree using React Developer Tools the component name shows correctly. The displayName just isn't being set during testing.

Let me know if you need more details. Thanks!

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

1 participant