|
| 1 | +/* eslint react/no-multi-comp: 0, react/prop-types: 0 */ |
| 2 | +import React from 'react'; |
| 3 | +import ReactDOM from 'react-dom'; |
| 4 | +import { shallow, mount } from 'enzyme'; |
| 5 | +import { Fade } from '../lib'; |
| 6 | + |
| 7 | +describe('Fade', () => { |
| 8 | + it('should render with "fade" class', () => { |
| 9 | + const wrapper = shallow(<Fade>Yo!</Fade>); |
| 10 | + |
| 11 | + expect(wrapper.hasClass('fade')).toBe(true); |
| 12 | + expect(wrapper.hasClass('in')).toBe(false); |
| 13 | + expect(wrapper.text()).toBe('Yo!'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should render additional classes', () => { |
| 17 | + const wrapper = shallow(<Fade className="other">Yo!</Fade>); |
| 18 | + |
| 19 | + expect(wrapper.hasClass('other')).toBe(true); |
| 20 | + expect(wrapper.hasClass('fade')).toBe(true); |
| 21 | + expect(wrapper.hasClass('in')).toBe(false); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should toggle "in" class with fadeIn & fadeOut', () => { |
| 25 | + const wrapper = mount(<Fade>Yo!</Fade>); |
| 26 | + const instance = wrapper.instance(); |
| 27 | + |
| 28 | + expect(wrapper.hasClass('in')).toBe(false); |
| 29 | + |
| 30 | + instance.fadeIn(); |
| 31 | + // hasClass does not pick up updates |
| 32 | + // maybe related https://github.com/airbnb/enzyme/issues/134 |
| 33 | + expect(ReactDOM.findDOMNode(instance).className).toBe('fade in'); |
| 34 | + |
| 35 | + instance.fadeOut(); |
| 36 | + |
| 37 | + expect(ReactDOM.findDOMNode(instance).className).toBe('fade'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should call fadeIn & fadeOut with delayed callbacks', () => { |
| 41 | + jasmine.clock().install(); |
| 42 | + |
| 43 | + const fadeInCallback = jasmine.createSpy('spy'); |
| 44 | + const fadeOutCallback = jasmine.createSpy('spy'); |
| 45 | + const wrapper = mount(<Fade>Yo!</Fade>); |
| 46 | + const instance = wrapper.instance(); |
| 47 | + |
| 48 | + expect(wrapper.hasClass('in')).toBe(false); |
| 49 | + |
| 50 | + instance.fadeIn(fadeInCallback, 250); |
| 51 | + expect(fadeInCallback).not.toHaveBeenCalled(); |
| 52 | + |
| 53 | + jasmine.clock().tick(250); |
| 54 | + expect(fadeInCallback).toHaveBeenCalled(); |
| 55 | + |
| 56 | + instance.fadeOut(fadeOutCallback, 250); |
| 57 | + expect(fadeOutCallback).not.toHaveBeenCalled(); |
| 58 | + |
| 59 | + jasmine.clock().tick(250); |
| 60 | + expect(fadeOutCallback).toHaveBeenCalled(); |
| 61 | + |
| 62 | + jasmine.clock().uninstall(); |
| 63 | + }); |
| 64 | +}); |
0 commit comments