Skip to content

Commit

Permalink
test(Button): check loading class with render, not only mount
Browse files Browse the repository at this point in the history
  • Loading branch information
akaguny committed Oct 14, 2019
1 parent c93f54c commit 1e33f88
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions components/button/__tests__/index.test.js
@@ -1,11 +1,13 @@
import React, { Component } from 'react';
import { render, mount } from 'enzyme';
import { render, mount, shallow } from 'enzyme';
import renderer from 'react-test-renderer';
import Button from '..';
import Icon from '../../icon';
import mountTest from '../../../tests/shared/mountTest';
import { sleep } from '../../../tests/utils';

jest.useFakeTimers();

describe('Button', () => {
mountTest(Button);
mountTest(() => <Button size="large" />);
Expand Down Expand Up @@ -129,7 +131,7 @@ describe('Button', () => {
expect(wrapper.find('.ant-btn-loading').length).toBe(1);
});

it('should change loading state with delay', () => {
fit('should change loading state with delay', () => {
// eslint-disable-next-line
class DefaultButton extends Component {
state = {
Expand All @@ -142,6 +144,7 @@ describe('Button', () => {

render() {
const { loading } = this.state;
console.log(loading);
return (
<Button loading={loading} onClick={this.enterLoading}>
Button
Expand All @@ -150,8 +153,11 @@ describe('Button', () => {
}
}
const wrapper = mount(<DefaultButton />);
expect(wrapper.render().hasClass('ant-btn-loading')).toBe(false);
wrapper.simulate('click');
expect(wrapper.hasClass('ant-btn-loading')).toBe(false);
expect(wrapper.render().hasClass('ant-btn-loading')).toBe(true);
jest.runOnlyPendingTimers();
expect(wrapper.render().hasClass('ant-btn-loading')).toBe(false);
});

it('should not clickable when button is loading', () => {
Expand Down

0 comments on commit 1e33f88

Please sign in to comment.