SHARE
TWEET

Untitled

a guest Jun 18th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class PlayButton extends Component {
  2.     constructor () {
  3.         super();
  4.  
  5.         this.state = { glow: false };
  6.         this.play = this.play.bind(this);
  7.     }
  8. componentDidUpdate () {
  9.         if (this.props.media.currentTime === 0 && this.props.media.duration !== 0 && !this.state.glow) {
  10.             console.log('entering')
  11.             setTimeout(() => {
  12.                 console.log('did time out')
  13.                 this.setState({ glow: true });
  14.             }, 3000);
  15.         }
  16.  
  17.         if (this.props.media.currentTime !== 0 && this.state.glow) {
  18.             this.setState({ glow: false });
  19.         }
  20.     }
  21.      
  22. it('button shoould start glowing', () => {
  23.         const wrapper = mount(<PlayButton media={{ currentTime: 0, duration: 1 }}/>);
  24.         wrapper.update()
  25.         jest.runAllTimers();
  26.         expect(wrapper.state('glow')).toBe(true);
  27.     });
  28.      
  29. it('button shoould start glowing', () => {
  30.         let clock = sinon.useFakeTimers();
  31.         const wrapper = mount(<PlayButton media={{ currentTime: 0, duration: 1 }}/>);
  32.         wrapper.update()
  33.         clock.tick(3000)
  34.         expect(wrapper.state('glow')).toBe(true);
  35.     });
  36.      
  37. static defaultProps = {
  38.     timeout: setTimeout
  39. }
  40.      
  41. this.props.timeout(() => {
  42.     console.log('did time out')
  43.     this.setState({ glow: true });
  44. }, 3000);
  45.      
  46. it('button shoould start glowing', () => {
  47.     const wrapper = mount(<PlayButton media={{ currentTime: 0, duration: 1 }}
  48.                                timeout={(fn, _) => fn()}}/>);
  49.     wrapper.update()
  50.     jest.runAllTimers();
  51.     expect(wrapper.state('glow')).toBe(true);
  52. });
  53.      
  54. const items = ['die Straße', 'die Adresse', 'die Nationalität'];
  55.  
  56. jest.useFakeTimers();
  57.  
  58. describe('<DelayedList />', () => {
  59.   test('it renders the items with delay', () => {
  60.     const component = shallow(
  61.       <DelayedList items={items} />
  62.     );
  63.  
  64.     jest.runAllTimers();
  65.     component.update(); // <--- force re-render of the component
  66.  
  67.     expect(component.state().currentIndex).toEqual(items.length);
  68.     expect(component).toMatchSnapshot();
  69.   });
  70. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top