Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { View } from 'react-native';
  3. import actions from './actions';
  4.  
  5. export class App extends Component {
  6. async componentDidMount() {
  7. console.log('In CDM');
  8. await actions.funcOne();
  9. await actions.funcTwo();
  10. console.log('Finished CDM');
  11. }
  12.  
  13. render() {
  14. return <View />;
  15. }
  16. }
  17.  
  18. const funcOne = async () => {
  19. console.log('One');
  20. };
  21.  
  22. const funcTwo = async () => {
  23. console.log('Two');
  24. };
  25.  
  26. export default { asyncOne: funcOne, asyncTwo: funcTwo };
  27.  
  28. import React from 'react';
  29. import { App } from '../App';
  30. import renderer from 'react-test-renderer';
  31.  
  32. import actions from '../actions';
  33.  
  34. const spyOne = jest.spyOn(actions, 'funcOne');
  35. const spyTwo = jest.spyOn(actions, 'funcTwo');
  36.  
  37. describe('App ', () => {
  38. test('does async stuff in expected order', async () => {
  39. console.log('Starting test');
  40. const tree = await renderer.create(<App />);
  41. console.log('About to expect');
  42. expect(spyOne).toHaveBeenCalled();
  43. console.log('Expect one to have been called');
  44. expect(spyTwo).toHaveBeenCalled();
  45. console.log('Expect two to have been called');
  46. expect(tree).toMatchSnapshot();
  47. });
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement