Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

BigClickableButton component test #350

Merged
merged 2 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"jsdom-global": "3.0.2",
"lint-staged": "7.2.0",
"loader-utils": "1.1.0",
"lolex": "3.0.0",
"mixpanel-browser": "2.22.4",
"moment": "2.22.2",
"postcss-flexbugs-fixes": "3.2.0",
Expand Down
30 changes: 30 additions & 0 deletions src/components/BigClickableButton/BigClickableButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable flowtype/require-valid-file-annotation */
import React from 'react';
import { mount } from 'enzyme';
import BigClickableButton from './BigClickableButton';
// Use Lolex to mock setTimeout - later use Jest mock once PR https://github.com/facebook/jest/pull/5171 landed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a // TODO so we don't forget

import lolex from 'lolex';

describe('BigClickableButton component', () => {
let wrapper;
let button;
lolex.install(); // mock setTimeout
Copy link
Collaborator

@melanieseltzer melanieseltzer Jan 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to uninstall after this is done? Not familiar with lolex but they are uninstalling in each example in their docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not familiar with Lolex but I think it's OK here to not call uninstall as we're only needing a static value for Date.now().

But if we would use it to test a spring at different tick positions we should add install to beforeEach and uninstall in afterEach - so we're having a fresh timer mock at each test.

I haven't tested a spring animation yet but clock.next() seems the way to test the next fired timeout event where clock = lolex.install() or clock.tick(100) to increment the timer by 100ms.


beforeEach(() => {
wrapper = mount(<BigClickableButton />);
button = wrapper.find('button');
jest.clearAllTimers();
button.simulate('mouseDown');
});

it('should render pressed', () => {
expect(wrapper.state('isActive')).toBeTruthy();
expect(wrapper).toMatchSnapshot();
});

it('should render released', () => {
button.simulate('mouseUp');
expect(wrapper.state('isActive')).toBeFalsy();
expect(wrapper).toMatchSnapshot();
});
});
Loading