Skip to content

Commit

Permalink
Merge pull request #180 from Andarist/fix/161-followup
Browse files Browse the repository at this point in the history
Refactored test - counter gets reset in beforeEach hook
  • Loading branch information
Pomax authored May 23, 2017
2 parents 2d9b0e3 + 77d9222 commit 370fefa
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ describe('onclickoutside hoc', function() {
});

describe('with child rendering as null', function() {
var counter;

beforeEach(function () {
counter = 0;
});

it('shouldn\'t throw an error when wrapped SFC renders as null', function() {
var StatelessComponent = () => null;
try {
Expand All @@ -303,7 +309,6 @@ describe('onclickoutside hoc', function() {
}
});

var counter;
class ClassComponent extends React.Component {
handleClickOutside() {
counter++;
Expand All @@ -325,16 +330,13 @@ describe('onclickoutside hoc', function() {
};

it('should render fine when wrapped component renders as null', function() {
counter = 0;
var component = rerender({ renderNull: true });
assert(component, 'component was wrapped despite having no DOM node on mount');
document.dispatchEvent(new Event('mousedown'));
assert(counter === 0, 'should not fire handleClickOutside when having no DOM node');
});

it('should attach and deattach event listener on updates', function() {
counter = 0;

rerender({ renderNull: false });
document.dispatchEvent(new Event('mousedown'));
assert(counter === 1, 'should fire handleClickOutside when DOM node gets created after rerender');
Expand All @@ -345,8 +347,6 @@ describe('onclickoutside hoc', function() {
});

it('should handle disabling and enabling onClickOutside listener when having no DOM node', function() {
counter = 0;

rerender({ renderNull: true, callEnableOnClickOutside: true });
document.dispatchEvent(new Event('mousedown'));
assert(counter === 0, 'should not call handleClickOutside when onClickOutside gets enabled when having no DOM node');
Expand Down

0 comments on commit 370fefa

Please sign in to comment.