|
1 | 1 | import React from 'react'
|
2 | 2 | import renderer from 'react-test-renderer'
|
3 | 3 |
|
4 |
| -import { createTests } from './utils' |
5 | 4 | import { Show as Show1 } from '../dist/index.cjs'
|
6 | 5 | import { Show as Show2 } from '../dist/index.esm'
|
7 | 6 | import Show3 from '../dist/Show'
|
8 | 7 | import Show4 from '../lib/Show'
|
9 | 8 |
|
10 |
| -const runTests = createTests(Show1, Show2, Show3, Show4) |
| 9 | +const describeEach = describe.each([Show1, Show2, Show3, Show4]) |
| 10 | +const input = <div>render me</div> |
11 | 11 |
|
12 |
| -runTests(Show => { |
13 |
| - const input = <div>render me</div> |
14 |
| - |
15 |
| - describe('with children', () => { |
16 |
| - test('should return primary content from children if when equals true', () => { |
17 |
| - const element = <Show when>{input}</Show> |
18 |
| - const component = renderer.create(element) |
19 |
| - expect(component.toJSON()).toMatchSnapshot() |
20 |
| - }) |
| 12 | +describeEach('with children', Show => { |
| 13 | + it('should return primary content from children if when equals true', () => { |
| 14 | + const element = <Show when>{input}</Show> |
| 15 | + const component = renderer.create(element) |
| 16 | + expect(component.toJSON()).toMatchSnapshot() |
| 17 | + }) |
21 | 18 |
|
22 |
| - test('should return null if when equals false', () => { |
23 |
| - const element = <Show when={false}>{input}</Show> |
24 |
| - const component = renderer.create(element) |
25 |
| - expect(component.toJSON()).toMatchSnapshot() |
26 |
| - }) |
| 19 | + it('should return null if when equals false', () => { |
| 20 | + const element = <Show when={false}>{input}</Show> |
| 21 | + const component = renderer.create(element) |
| 22 | + expect(component.toJSON()).toMatchSnapshot() |
27 | 23 | })
|
| 24 | +}) |
28 | 25 |
|
29 |
| - describe('with render', () => { |
30 |
| - test('should return primary content from render if when equals true', () => { |
31 |
| - const element = <Show when render={() => input} /> |
32 |
| - const component = renderer.create(element) |
33 |
| - expect(component.toJSON()).toMatchSnapshot() |
34 |
| - }) |
| 26 | +describeEach('with render', Show => { |
| 27 | + it('should return primary content from render if when equals true', () => { |
| 28 | + const element = <Show when render={() => input} /> |
| 29 | + const component = renderer.create(element) |
| 30 | + expect(component.toJSON()).toMatchSnapshot() |
| 31 | + }) |
35 | 32 |
|
36 |
| - test('should return null if when equals false', () => { |
37 |
| - const element = <Show when={false} render={() => input} /> |
38 |
| - const component = renderer.create(element) |
39 |
| - expect(component.toJSON()).toMatchSnapshot() |
40 |
| - }) |
| 33 | + it('should return null if when equals false', () => { |
| 34 | + const element = <Show when={false} render={() => input} /> |
| 35 | + const component = renderer.create(element) |
| 36 | + expect(component.toJSON()).toMatchSnapshot() |
| 37 | + }) |
41 | 38 |
|
42 |
| - test('should not evaluate render if when is undefined', () => { |
43 |
| - const obj = undefined |
44 |
| - const element = <Show when={!!obj} render={() => <div>{obj.label}</div>} /> |
45 |
| - const component = renderer.create(element) |
46 |
| - expect(component.toJSON()).toMatchSnapshot() |
47 |
| - }) |
| 39 | + it('should not evaluate render if when is undefined', () => { |
| 40 | + const obj = undefined |
| 41 | + const element = <Show when={!!obj} render={() => <div>{obj.label}</div>} /> |
| 42 | + const component = renderer.create(element) |
| 43 | + expect(component.toJSON()).toMatchSnapshot() |
48 | 44 | })
|
| 45 | +}) |
49 | 46 |
|
50 |
| - describe('with children and render', () => { |
51 |
| - const renderInput = <div>render</div> |
52 |
| - const childrenInput = <div>children</div> |
| 47 | +describeEach('with children and render', Show => { |
| 48 | + const renderInput = <div>render</div> |
| 49 | + const childrenInput = <div>children</div> |
53 | 50 |
|
54 |
| - test('should return primary content from children and ignore render if when equals true', () => { |
55 |
| - const element = ( |
56 |
| - <Show when render={() => renderInput}> |
57 |
| - {childrenInput} |
58 |
| - </Show> |
59 |
| - ) |
60 |
| - const component = renderer.create(element) |
61 |
| - expect(component.toJSON()).toMatchSnapshot() |
62 |
| - }) |
| 51 | + it('should return primary content from children and ignore render if when equals true', () => { |
| 52 | + const element = ( |
| 53 | + <Show when render={() => renderInput}> |
| 54 | + {childrenInput} |
| 55 | + </Show> |
| 56 | + ) |
| 57 | + const component = renderer.create(element) |
| 58 | + expect(component.toJSON()).toMatchSnapshot() |
| 59 | + }) |
63 | 60 |
|
64 |
| - test('should return null if when equals false', () => { |
65 |
| - const element = ( |
66 |
| - <Show when={false} render={() => renderInput}> |
67 |
| - {childrenInput} |
68 |
| - </Show> |
69 |
| - ) |
70 |
| - const component = renderer.create(element) |
71 |
| - expect(component.toJSON()).toMatchSnapshot() |
72 |
| - }) |
| 61 | + it('should return null if when equals false', () => { |
| 62 | + const element = ( |
| 63 | + <Show when={false} render={() => renderInput}> |
| 64 | + {childrenInput} |
| 65 | + </Show> |
| 66 | + ) |
| 67 | + const component = renderer.create(element) |
| 68 | + expect(component.toJSON()).toMatchSnapshot() |
73 | 69 | })
|
| 70 | +}) |
74 | 71 |
|
75 |
| - describe('without children and render', () => { |
76 |
| - test('should return null', () => { |
77 |
| - const element = <Show when /> |
78 |
| - const component = renderer.create(element) |
79 |
| - expect(component.toJSON()).toMatchSnapshot() |
80 |
| - }) |
| 72 | +describeEach('without children and render', Show => { |
| 73 | + it('should return null', () => { |
| 74 | + const element = <Show when /> |
| 75 | + const component = renderer.create(element) |
| 76 | + expect(component.toJSON()).toMatchSnapshot() |
81 | 77 | })
|
82 | 78 | })
|
0 commit comments