SHARE
TWEET

Untitled

a guest May 19th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import {configure, mount} from 'enzyme';
  3. import Adapter from 'enzyme-adapter-react-16';
  4.  
  5. import ArtistQuestionScreen from './artist-question-screen';
  6.  
  7. configure({adapter: new Adapter()});
  8.  
  9. const mock = {
  10.   question: {
  11.     type: `artist`,
  12.     song: {
  13.       artist: `Jim Beam`,
  14.       src: `path.mp3`,
  15.     },
  16.     answers: [
  17.       {
  18.         picture: `path.jpg`,
  19.         artist: `John Snow`,
  20.       },
  21.       {
  22.         picture: `path.jpg`,
  23.         artist: `Jack Daniels`,
  24.       },
  25.       {
  26.         picture: `path.jpg`,
  27.         artist: `Jim Beam`,
  28.       },
  29.     ],
  30.   },
  31. };
  32.  
  33. // вот этот тест у меня пройдёт
  34. it(`When user chose variant in artist question onAnswer handler fired once -- change emulation`, () => {
  35.   const {question} = mock;
  36.   const onAnswer = jest.fn();
  37.   const wrapper = mount((
  38.     <ArtistQuestionScreen
  39.       onAnswer={onAnswer}
  40.       question={question}
  41.     />
  42.   ));
  43.  
  44.   const form = wrapper.find(`form`);
  45.   form.simulate(`change`);
  46.  
  47.   expect(onAnswer).toHaveBeenCalledTimes(1);
  48. });
  49.  
  50. // а вот этот нет
  51. it(`When user chose variant in artist question onAnswer handler fired once -- click emulation`, () => {
  52.   const {question} = mock;
  53.   const onAnswer = jest.fn();
  54.   const wrapper = mount((
  55.     <ArtistQuestionScreen
  56.       onAnswer={onAnswer}
  57.       question={question}
  58.     />
  59.   ));
  60.  
  61.   const lastArtistPic = wrapper.find(`.artist__picture`).last();
  62.   lastArtistPic.simulate(`click`);
  63.  
  64.   expect(onAnswer).toHaveBeenCalledTimes(1);
  65.  
  66. });
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
 
Top