Skip to content
This repository has been archived by the owner on Dec 24, 2019. It is now read-only.

Commit

Permalink
Allow onDismiss to be called without prop update
Browse files Browse the repository at this point in the history
* Allow onDismiss to be called without prop update

* Test onDismiss firing correctly with no prop change
  • Loading branch information
joewang704 authored and Patrick Burtchaell committed Jun 26, 2016
1 parent 53a53ee commit 0d5d4c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class Notification extends Component {
this.getActionStyle = this.getActionStyle.bind(this);
this.getTitleStyle = this.getTitleStyle.bind(this);
this.handleClick = this.handleClick.bind(this);

if (this.props.onDismiss && this.props.isActive) {
this.dismissTimeout = setTimeout(
this.props.onDismiss,
this.props.dismissAfter
);
}
}

componentWillReceiveProps(nextProps) {
Expand Down
22 changes: 22 additions & 0 deletions test/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,26 @@ describe('<Notification />', () => {
}
}, mockNotification.dismissAfter);
});

it('onDismiss fires correctly without prop change', done => {
const handleDismiss = spy();

const wrapper = mount(
<Notification
message={mockNotification.message}
dismissAfter={mockNotification.dismissAfter}
onDismiss={handleDismiss}
isActive
/>
);

setTimeout(() => {
try {
expect(handleDismiss.calledOnce).to.equal(true);
done();
} catch (e) {
done(e);
}
}, mockNotification.dismissAfter);
})
});

0 comments on commit 0d5d4c4

Please sign in to comment.