Skip to content

Commit 88d6001

Browse files
committed
Move test components to test
1 parent d4518ba commit 88d6001

File tree

2 files changed

+48
-50
lines changed

2 files changed

+48
-50
lines changed

tests/index.spec.tsx

+48-28
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,29 @@ import * as React from 'react';
22
import { expect } from 'chai';
33
import { createReactStub } from '../src';
44
import { $render } from './render-helper';
5-
import { BarProps, Foo } from './test-components';
65

76
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+
828
it('should stub render calls', function () {
929
const Bar = createReactStub<BarProps>();
1030
Bar.withProps({ bar: 42 }).renders(<span>I am Bar</span>);
@@ -26,33 +46,6 @@ describe('createStub', () => {
2646
expect($foo.text()).to.contain('call 2');
2747
});
2848

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-
5649
it('should spy on render calls', function () {
5750
const Bar = createReactStub<BarProps>();
5851

@@ -85,4 +78,31 @@ describe('createStub', () => {
8578

8679
expect(Bar.props).to.deep.equal([{ bar: 1 }, { bar: 2 }]);
8780
});
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+
});
88108
});

tests/test-components.tsx

-22
This file was deleted.

0 commit comments

Comments
 (0)