Skip to content

Commit

Permalink
shouldCloseOnEsc: Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
spen committed Aug 27, 2017
1 parent b908042 commit 1685e59
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions specs/Modal.events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,38 @@ describe('Events', () => {
expect(document.activeElement).toEqual(content);
});

it('should close on Esc key event', () => {
const requestCloseCallback = sinon.spy();
const modal = renderModal({
isOpen: true,
shouldCloseOnOverlayClick: true,
onRequestClose: requestCloseCallback
describe('shouldCloseOnEsc', () => {
context('when true', () => {
it('should close on Esc key event', () => {
const requestCloseCallback = sinon.spy();
const modal = renderModal({
isOpen: true,
shouldCloseOnEsc: true,
onRequestClose: requestCloseCallback
});
escKeyDown(mcontent(modal));
expect(requestCloseCallback.called).toBeTruthy();
// Check if event is passed to onRequestClose callback.
const event = requestCloseCallback.getCall(0).args[0];
expect(event).toExist();
});
});

context('when false', () => {
it('should not close on Esc key event', () => {
const requestCloseCallback = sinon.spy();
const modal = renderModal({
isOpen: true,
shouldCloseOnEsc: false,
onRequestClose: requestCloseCallback
});
escKeyDown(mcontent(modal));
expect(requestCloseCallback.called).toEqual(false);
});
});
escKeyDown(mcontent(modal));
expect(requestCloseCallback.called).toBeTruthy();
// Check if event is passed to onRequestClose callback.
const event = requestCloseCallback.getCall(0).args[0];
expect(event).toExist();
});

describe('shouldCloseOnoverlayClick', () => {
describe('shouldCloseOnOverlayClick', () => {
it('when false, click on overlay should not close', () => {
const requestCloseCallback = sinon.spy();
const modal = renderModal({
Expand Down

0 comments on commit 1685e59

Please sign in to comment.