enzymejs / enzyme-matchers

Jasmine/Jest assertions for enzyme
MIT License
892 stars 116 forks source link

Incorrect flow typing for getDisplayName #309

Closed bz2 closed 5 years ago

bz2 commented 5 years ago

Regression from new code in https://github.com/FormidableLabs/enzyme-matchers/pull/306 flow check no longer passes if using enzyme-matchers:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/enzyme-matchers/lib/utils/displayName.js.flow:8:12

Cannot return undefined because undefined [1] is incompatible with string [2].

     node_modules/enzyme-matchers/lib/utils/displayName.js.flow
 [2]  3│ export default function getDisplayName(Component: Function | string): string {
      4│   if (typeof Component === 'string') {
      5│     return Component;
      6│   }
      7│   if (!Component) {
      8│     return undefined;
      9│   }
     10│   return Component.displayName || Component.name || 'Component';
     11│ }

     /tmp/flow/flowlib_9125ad1/core.js
 [1] 13│ declare var undefined: void;

Found 1 error
bz2 commented 5 years ago

The workaround is to treat enzyme-matchers as not having any usable flow types, in .flowconfig:

[untyped]
<PROJECT_ROOT>/node_modules/enzyme-matchers/.*