File size: 832 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* eslint-env jest */
import { Component } from 'react'
import { getDisplayName } from 'next/dist/shared/lib/utils'

describe('getDisplayName', () => {
  it('gets the proper display name of a component', () => {
    class ComponentOne extends Component {
      render() {
        return null
      }
    }

    class ComponentTwo extends Component {
      static displayName = 'CustomDisplayName'
      render() {
        return null
      }
    }

    function FunctionalComponent() {
      return null
    }

    expect(getDisplayName(ComponentOne)).toBe('ComponentOne')
    expect(getDisplayName(ComponentTwo)).toBe('CustomDisplayName')
    expect(getDisplayName(FunctionalComponent)).toBe('FunctionalComponent')
    expect(getDisplayName(() => null)).toBe('Unknown')
    expect(getDisplayName('div' as any)).toBe('div')
  })
})