-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: write unit tests for existing components
- Loading branch information
Showing
12 changed files
with
169 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
|
||
import { testId } from './AppBar'; | ||
import { AppBar, Text } from '..'; | ||
|
||
describe('<AppBar />', () => { | ||
it('should render children', () => { | ||
const { getByTestId } = render( | ||
<AppBar> | ||
<Text>This is an AppBar</Text> | ||
</AppBar> | ||
); | ||
|
||
expect(getByTestId(testId)).toHaveTextContent('This is an AppBar'); | ||
}); | ||
|
||
it('should render custom styles', () => { | ||
const style = { marginTop: 42 }; | ||
|
||
const { getByTestId } = render( | ||
<AppBar style={style}> | ||
<Text>This is an AppBar</Text> | ||
</AppBar> | ||
); | ||
|
||
expect(getByTestId(testId)).toHaveStyle(style); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react-native'; | ||
|
||
import { blockSizes, ButtonSizes, testId } from './Button'; | ||
import { Button, Text } from '..'; | ||
|
||
const noop = () => {}; | ||
|
||
describe('<Button />', () => { | ||
it('should render children', () => { | ||
const { getByText } = render( | ||
<Button onPress={noop}> | ||
<Text>Potato</Text> | ||
</Button> | ||
); | ||
|
||
expect(getByText('Potato')).toBeTruthy(); | ||
}); | ||
|
||
it('should fire press', () => { | ||
const onButtonPress = jest.fn(); | ||
|
||
const { getByTestId } = render( | ||
<Button onPress={onButtonPress}> | ||
<Text>Ok</Text> | ||
</Button> | ||
); | ||
|
||
fireEvent(getByTestId(testId), 'press'); | ||
expect(onButtonPress).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should handle square sizes', () => { | ||
const sizes: ButtonSizes[] = ['sm', 'md', 'lg']; | ||
|
||
sizes.forEach(size => { | ||
const { getByTestId } = render( | ||
<Button onPress={noop} size={size} square> | ||
<Text>Ok</Text> | ||
</Button> | ||
); | ||
|
||
expect(getByTestId(testId)).toHaveStyle({ width: blockSizes[size] }); | ||
}); | ||
}); | ||
|
||
it('should render custom styles', () => { | ||
const style = { backgroundColor: 'papayawhip' }; | ||
|
||
const { getByTestId } = render( | ||
<Button onPress={noop} style={style}> | ||
<Text>Ok</Text> | ||
</Button> | ||
); | ||
|
||
expect(getByTestId(testId)).toHaveStyle(style); | ||
}); | ||
|
||
it('should render a full width button', () => { | ||
const { getByTestId } = render( | ||
<Button onPress={noop} fullWidth> | ||
<Text>Ok</Text> | ||
</Button> | ||
); | ||
|
||
expect(getByTestId(testId)).toHaveStyle({ width: '100%' }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
|
||
import { testId } from './Panel'; | ||
import { Panel, Text } from '..'; | ||
|
||
describe('<Panel />', () => { | ||
it('should render children', () => { | ||
const { getByTestId } = render( | ||
<Panel> | ||
<Text>Banana dance</Text> | ||
</Panel> | ||
); | ||
|
||
expect(getByTestId(testId)).toHaveTextContent('Banana dance'); | ||
}); | ||
|
||
it('should render custom styles', () => { | ||
const style = { backgroundColor: 'teal' }; | ||
|
||
const { getByTestId } = render( | ||
<Panel style={style}> | ||
<Text>Panel</Text> | ||
</Panel> | ||
); | ||
|
||
expect(getByTestId(testId)).toHaveStyle(style); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
|
||
import { Text } from '..'; | ||
|
||
describe('<Text />', () => { | ||
it('should render children', () => { | ||
const { getByText } = render(<Text>Potato</Text>); | ||
|
||
expect(getByText('Potato')).toBeTruthy(); | ||
}); | ||
|
||
it('should render custom styles', () => { | ||
const style = { color: 'papayawhip' }; | ||
|
||
const { getByText } = render(<Text style={style}>Potato</Text>); | ||
|
||
expect(getByText('Potato')).toHaveStyle(style); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters