Skip to content

Commit 830a566

Browse files
author
Artur Yorsh
committed
test(theme): add theme consumer tests
1 parent efaf224 commit 830a566

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/framework/theme/theme.spec.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,42 @@ import * as UITest from 'react-native-testing-library';
44
import {ThemeProvider, withTheme, WithThemeProps} from './index';
55

66
interface TestProps extends WithThemeProps {
7-
name: string;
7+
testId: string;
88
}
99

1010
class TestComponent extends React.Component<TestProps> {
1111
render() {
12-
const {theme, name} = this.props;
13-
12+
console.info(`TestComponent theme prop: ${JSON.stringify(this.props.theme)}`);
1413
return (
15-
<View/>
14+
<View testID={this.props.testId}/>
1615
);
1716
}
1817
}
1918

20-
it('Checks simple Provider/Consumer theme pass', async () => {
19+
it('Checks theme consumer renders properly', async () => {
2120
const ThemedComponent = withTheme(TestComponent);
21+
const themedComponentTestId = '@theme/root';
2222

2323
const component = UITest.render(
24-
<ThemeProvider>
25-
<ThemedComponent name={'test'}/>
24+
<ThemeProvider theme={{}}>
25+
<ThemedComponent testId={themedComponentTestId}/>
2626
</ThemeProvider>,
2727
);
2828

29-
// TODO: finish test
29+
const themedComponent = component.getByTestId(themedComponentTestId);
30+
expect(themedComponent).not.toBeNull();
3031
});
3132

33+
it('Checks theme consumer receives theme prop', async () => {
34+
const ThemedComponent = withTheme(TestComponent);
35+
const themedComponentTestId = '@theme/root';
36+
37+
const component = UITest.render(
38+
<ThemeProvider theme={{}}>
39+
<ThemedComponent testId={themedComponentTestId}/>
40+
</ThemeProvider>,
41+
);
42+
43+
const themedComponent = component.getByTestId(themedComponentTestId);
44+
expect(themedComponent.props.theme).not.toBeNull();
45+
});

0 commit comments

Comments
 (0)