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

Conversation

AWolf81
Copy link
Collaborator

@AWolf81 AWolf81 commented Jan 15, 2019

Related Issue:
#309

Summary:
Two snapshot tests for button states.

Added lolex devDependency to mock setTimeout used by React-Spring. Otherwise every test run was creating a different snapshot because _idleStart changed.
We can remove Lolex later as it will be added to Jest but that's not ready yet. See link to PR in code comment.

@codecov
Copy link

codecov bot commented Jan 15, 2019

Codecov Report

Merging #350 into master will increase coverage by 0.73%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #350      +/-   ##
==========================================
+ Coverage   24.91%   25.64%   +0.73%     
==========================================
  Files         152      152              
  Lines        3625     3618       -7     
  Branches      388      388              
==========================================
+ Hits          903      928      +25     
+ Misses       2450     2420      -30     
+ Partials      272      270       -2
Impacted Files Coverage Δ
...omponents/BigClickableButton/BigClickableButton.js 100% <0%> (+100%) ⬆️

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.

Copy link
Collaborator

@melanieseltzer melanieseltzer left a comment

Choose a reason for hiding this comment

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

This LGTM! Just add the todo comment then let's get it merged.

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

@AWolf81 AWolf81 merged commit 278edf8 into master Jan 21, 2019
@AWolf81 AWolf81 deleted the test-big-clickable-button branch January 21, 2019 21:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants