@@ -2,9 +2,29 @@ import * as React from 'react';
2
2
import { expect } from 'chai' ;
3
3
import { createReactStub } from '../src' ;
4
4
import { $render } from './render-helper' ;
5
- import { BarProps , Foo } from './test-components' ;
6
5
7
6
describe ( 'createStub' , ( ) => {
7
+ interface BarProps {
8
+ bar : number ;
9
+ }
10
+
11
+ interface FooProps {
12
+ // eslint-disable-next-line no-use-before-define
13
+ Bar : React . ComponentType < BarProps > ;
14
+ testbar ?: number ;
15
+ }
16
+
17
+ class Foo extends React . Component < FooProps > {
18
+ public static defaultProps : Partial < FooProps > = {
19
+ testbar : 42
20
+ } ;
21
+
22
+ render ( ) {
23
+ const { Bar, testbar } = this . props ;
24
+ return < Bar bar = { testbar as number } /> ;
25
+ }
26
+ }
27
+
8
28
it ( 'should stub render calls' , function ( ) {
9
29
const Bar = createReactStub < BarProps > ( ) ;
10
30
Bar . withProps ( { bar : 42 } ) . renders ( < span > I am Bar</ span > ) ;
@@ -26,33 +46,6 @@ describe('createStub', () => {
26
46
expect ( $foo . text ( ) ) . to . contain ( 'call 2' ) ;
27
47
} ) ;
28
48
29
- describe ( 'partial props' , function ( ) {
30
- interface MultipleProps {
31
- foo1 : number ;
32
- foo2 : number ;
33
- }
34
-
35
- const X = ( { MultipleProps } : { MultipleProps : React . ComponentType < MultipleProps > } ) =>
36
- < MultipleProps foo1 = { 1 } foo2 = { 2 } /> ;
37
-
38
- it ( 'should stub render calls' , function ( ) {
39
- const M = createReactStub < MultipleProps > ( ) ;
40
- M . withProps ( { foo1 : 1 } ) . renders ( < span > foobar</ span > ) ;
41
-
42
- const $x = $render ( < X MultipleProps = { M } /> ) ;
43
-
44
- expect ( $x . text ( ) ) . to . contain ( 'foobar' ) ;
45
- } ) ;
46
-
47
- it ( 'should spy on render calls' , function ( ) {
48
- const M = createReactStub < MultipleProps > ( ) ;
49
-
50
- $render ( < X MultipleProps = { M } /> ) ;
51
-
52
- expect ( M . renderedWith ( { foo1 : 1 } ) ) . to . be . true ;
53
- } ) ;
54
- } ) ;
55
-
56
49
it ( 'should spy on render calls' , function ( ) {
57
50
const Bar = createReactStub < BarProps > ( ) ;
58
51
@@ -85,4 +78,31 @@ describe('createStub', () => {
85
78
86
79
expect ( Bar . props ) . to . deep . equal ( [ { bar : 1 } , { bar : 2 } ] ) ;
87
80
} ) ;
81
+
82
+ describe ( 'partial props' , function ( ) {
83
+ interface MultipleProps {
84
+ foo1 : number ;
85
+ foo2 : number ;
86
+ }
87
+
88
+ const X = ( { MultipleProps } : { MultipleProps : React . ComponentType < MultipleProps > } ) =>
89
+ < MultipleProps foo1 = { 1 } foo2 = { 2 } /> ;
90
+
91
+ it ( 'should stub render calls' , function ( ) {
92
+ const M = createReactStub < MultipleProps > ( ) ;
93
+ M . withProps ( { foo1 : 1 } ) . renders ( < span > foobar</ span > ) ;
94
+
95
+ const $x = $render ( < X MultipleProps = { M } /> ) ;
96
+
97
+ expect ( $x . text ( ) ) . to . contain ( 'foobar' ) ;
98
+ } ) ;
99
+
100
+ it ( 'should spy on render calls' , function ( ) {
101
+ const M = createReactStub < MultipleProps > ( ) ;
102
+
103
+ $render ( < X MultipleProps = { M } /> ) ;
104
+
105
+ expect ( M . renderedWith ( { foo1 : 1 } ) ) . to . be . true ;
106
+ } ) ;
107
+ } ) ;
88
108
} ) ;
0 commit comments