Skip to content

Commit

Permalink
fix: add tests for snackbar visibility on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibarabas authored and satya164 committed Nov 5, 2018
1 parent e4a48ba commit 8764f60
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/components/Snackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ class Snackbar extends React.Component<Props, State> {
};

componentDidMount() {
this._toggle();
if (this.props.visible) {
this._show();
}
}

componentDidUpdate(prevProps) {
Expand Down
15 changes: 14 additions & 1 deletion src/components/__tests__/Snackbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ import renderer from 'react-test-renderer';
import { Text } from 'react-native';
import Snackbar from '../Snackbar';

jest.useFakeTimers();
// Make sure any animation finishes before checking the snapshot results
jest.mock('Animated', () => {
const ActualAnimated = jest.requireActual('Animated');

return {
...ActualAnimated,
timing: (value, config) => ({
start: callback => {
value.setValue(config.toValue);
callback && callback({ finished: true });
},
}),
};
});

it('renders snackbar with content', () => {
const tree = renderer
Expand Down
12 changes: 6 additions & 6 deletions src/components/__tests__/__snapshots__/Snackbar.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ exports[`renders snackbar with Text as a child 1`] = `
pointerEvents="box-none"
style={
Object {
"opacity": 0,
"opacity": 1,
"transform": Array [
Object {
"scale": 0.9,
"scale": 1,
},
],
}
Expand Down Expand Up @@ -145,10 +145,10 @@ exports[`renders snackbar with action button 1`] = `
pointerEvents="box-none"
style={
Object {
"opacity": 0,
"opacity": 1,
"transform": Array [
Object {
"scale": 0.9,
"scale": 1,
},
],
}
Expand Down Expand Up @@ -350,10 +350,10 @@ exports[`renders snackbar with content 1`] = `
pointerEvents="box-none"
style={
Object {
"opacity": 0,
"opacity": 1,
"transform": Array [
Object {
"scale": 0.9,
"scale": 1,
},
],
}
Expand Down

0 comments on commit 8764f60

Please sign in to comment.