Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PlayButton extends Component {
- constructor () {
- super();
- this.state = { glow: false };
- this.play = this.play.bind(this);
- }
- componentDidUpdate () {
- if (this.props.media.currentTime === 0 && this.props.media.duration !== 0 && !this.state.glow) {
- console.log('entering')
- setTimeout(() => {
- console.log('did time out')
- this.setState({ glow: true });
- }, 3000);
- }
- if (this.props.media.currentTime !== 0 && this.state.glow) {
- this.setState({ glow: false });
- }
- }
- it('button shoould start glowing', () => {
- const wrapper = mount(<PlayButton media={{ currentTime: 0, duration: 1 }}/>);
- wrapper.update()
- jest.runAllTimers();
- expect(wrapper.state('glow')).toBe(true);
- });
- it('button shoould start glowing', () => {
- let clock = sinon.useFakeTimers();
- const wrapper = mount(<PlayButton media={{ currentTime: 0, duration: 1 }}/>);
- wrapper.update()
- clock.tick(3000)
- expect(wrapper.state('glow')).toBe(true);
- });
- static defaultProps = {
- timeout: setTimeout
- }
- this.props.timeout(() => {
- console.log('did time out')
- this.setState({ glow: true });
- }, 3000);
- it('button shoould start glowing', () => {
- const wrapper = mount(<PlayButton media={{ currentTime: 0, duration: 1 }}
- timeout={(fn, _) => fn()}}/>);
- wrapper.update()
- jest.runAllTimers();
- expect(wrapper.state('glow')).toBe(true);
- });
- const items = ['die Straße', 'die Adresse', 'die Nationalität'];
- jest.useFakeTimers();
- describe('<DelayedList />', () => {
- test('it renders the items with delay', () => {
- const component = shallow(
- <DelayedList items={items} />
- );
- jest.runAllTimers();
- component.update(); // <--- force re-render of the component
- expect(component.state().currentIndex).toEqual(items.length);
- expect(component).toMatchSnapshot();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement