Skip to content

Commit

Permalink
[Tests] useEffect: Fix set document title test
Browse files Browse the repository at this point in the history
  • Loading branch information
chenesan authored and ljharb committed Jun 11, 2019
1 parent 9abded2 commit d9fa3f0
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions packages/enzyme-test-suite/test/shared/hooks/useEffect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import sinon from 'sinon-sandbox';

import {
describeIf,
itIf,
} from '../../_helpers';

import {
is,
} from '../../_helpers/version';
import {
useEffect,
useState,
Expand Down Expand Up @@ -158,26 +161,27 @@ export default function describeUseEffect({
expect(setDocumentTitle.args).to.deep.equal([[expectedCountString(0)]]);
});

// TODO: useEffect fixme
it.skip('on didupdate', () => {
it('on didupdate', () => {
const wrapper = Wrap(<ClickCounterPage />);

expect(setDocumentTitle).to.have.property('callCount', 1);
expect(setDocumentTitle.args).to.deep.equal([[expectedCountString(0)]]);
const [firstCall] = setDocumentTitle.args;
expect(firstCall).to.deep.equal([expectedCountString(0)]);
expect(wrapper.find('p').text()).to.equal(expectedCountString(0));

const { onClick } = wrapper.find('button').props();
onClick();
wrapper.find('button').invoke('onClick')();

expect(setDocumentTitle).to.have.property('callCount', 2);
expect(setDocumentTitle.args).to.deep.equal([[expectedCountString(1)]]);
const [, secondCall] = setDocumentTitle.args;
expect(secondCall).to.deep.equal([expectedCountString(1)]);
expect(wrapper.find('p').text()).to.equal(expectedCountString(1));

onClick();
onClick();
wrapper.find('button').invoke('onClick')();
wrapper.find('button').invoke('onClick')();

expect(setDocumentTitle).to.have.property('callCount', 4);
expect(setDocumentTitle.args).to.deep.equal([[expectedCountString(3)]]);
const [,,, fourthCall] = setDocumentTitle.args;
expect(fourthCall).to.deep.equal([expectedCountString(3)]);
expect(wrapper.find('p').text()).to.equal(expectedCountString(3));
});
});
Expand Down Expand Up @@ -235,12 +239,14 @@ export default function describeUseEffect({
expect(wrapper.html()).to.eql('Online');
});

it('cleanup on unmount', () => {
itIf(is('> 16.8.3'), 'cleanup on unmount', () => {
const wrapper = Wrap(<FriendStatus friend={friend} />);

wrapper.unmount();

expect(ChatAPI.unsubscribeFromFriendStatus.calledOnceWith(friend.id)).to.equal(true);
expect(ChatAPI.unsubscribeFromFriendStatus).to.have.property('callCount', 1);
const [[firstArg]] = ChatAPI.unsubscribeFromFriendStatus.args;
expect(firstArg).to.equal(friend.id);
});
});
});
Expand Down

0 comments on commit d9fa3f0

Please sign in to comment.