1 | const React = require('react');
|
2 | const isReact = require('../');
|
3 |
|
4 |
|
5 | class Foo extends React.Component {
|
6 | render() {
|
7 | return <h1>Hello</h1>;
|
8 | }
|
9 | }
|
10 |
|
11 | const foo = <Foo />;
|
12 |
|
13 | //Functional Component
|
14 | function Bar(props) {
|
15 | return <h1>World</h1>;
|
16 | }
|
17 | const bar = <Bar />;
|
18 | const Func = () => <h2>implicit</h2>;
|
19 |
|
20 | // React Element
|
21 | const header = <h1>Title</h1>;
|
22 |
|
23 | it('Classifies class component', () => {
|
24 | expect(isReact.compatible(Foo)).toBe(true);
|
25 | expect(isReact.component(Foo)).toBe(true);
|
26 | expect(isReact.classComponent(Foo)).toBe(true);
|
27 | expect(isReact.functionComponent(Foo)).toBe(false);
|
28 | expect(isReact.element(Foo)).toBe(false);
|
29 | });
|
30 |
|
31 | it('Classifies composite element from class component', () => {
|
32 | expect(isReact.compatible(Foo)).toBe(true);
|
33 | expect(isReact.component(Foo)).toBe(true);
|
34 | expect(isReact.classComponent(Foo)).toBe(true);
|
35 | expect(isReact.functionComponent(Foo)).toBe(false);
|
36 | expect(isReact.element(Foo)).toBe(false);
|
37 | });
|
38 |
|
39 | it('Classifies function component', () => {
|
40 | expect(isReact.compatible(Bar)).toBe(true);
|
41 | expect(isReact.component(Bar)).toBe(true);
|
42 | expect(isReact.classComponent(Bar)).toBe(false);
|
43 | expect(isReact.functionComponent(Bar)).toBe(true);
|
44 | expect(isReact.element(Bar)).toBe(false);
|
45 | expect(isReact.compatible(Func)).toBe(true);
|
46 | expect(isReact.component(Func)).toBe(true);
|
47 | expect(isReact.classComponent(Func)).toBe(false);
|
48 | expect(isReact.functionComponent(Func)).toBe(true);
|
49 | expect(isReact.element(Func)).toBe(false);
|
50 | });
|
51 |
|
52 | it('Classifies composite element from function component', () => {
|
53 | expect(isReact.compatible(Bar)).toBe(true);
|
54 | expect(isReact.component(Bar)).toBe(true);
|
55 | expect(isReact.classComponent(Bar)).toBe(false);
|
56 | expect(isReact.functionComponent(Bar)).toBe(true);
|
57 | expect(isReact.element(Bar)).toBe(false);
|
58 | });
|
59 |
|
60 | it('Classifies DOM type element', () => {
|
61 | expect(isReact.compatible(header)).toBe(true);
|
62 | expect(isReact.component(header)).toBe(false);
|
63 | expect(isReact.element(header)).toBe(true);
|
64 | expect(isReact.DOMTypeElement(header)).toBe(true);
|
65 | expect(isReact.compositeTypeElement(header)).toBe(false);
|
66 | });
|
67 |
|
68 | describe('Native JavaScript', () => {
|
69 | it('Object is not valid React', () => {
|
70 | expect(isReact.compatible({})).toBe(false);
|
71 | });
|
72 |
|
73 | it('Array is not valid React', () => {
|
74 | expect(isReact.compatible({})).toBe(false);
|
75 | });
|
76 |
|
77 | it('Number is not valid React', () => {
|
78 | expect(isReact.compatible(1)).toBe(false);
|
79 | });
|
80 |
|
81 | it('String is not valid React', () => {
|
82 | expect(isReact.compatible('Hello, world')).toBe(false);
|
83 | });
|
84 |
|
85 | it('Function is not valid React', () => {
|
86 | expect(isReact.compatible(() => {})).toBe(false);
|
87 | });
|
88 |
|
89 | it('null is not valid React', () => {
|
90 | expect(isReact.compatible(null)).toBe(false);
|
91 | });
|
92 |
|
93 | it('undefined is not valid React', () => {
|
94 | expect(isReact.compatible(undefined)).toBe(false);
|
95 | });
|
96 | });
|
97 |
|
\ | No newline at end of file |