daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Sep 18th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     App.test.js
  3. */
  4.  
  5. import React from 'react'
  6. import { mount } from 'enzyme'
  7. import App from './App'
  8. import Blog from './components/blogs/Blog'
  9. jest.mock('./services/blogs')
  10.  
  11. import blogService from './services/blogs'
  12.  
  13. describe('<App />', () => {
  14.   let app
  15.   beforeAll(() => {
  16.       /*test throws:
  17.      
  18.         console.error node_modules/react-dom/cjs/react-dom.development.js:9747
  19.         The above error occurred in the <App> component:
  20.           in App (created by WrapperComponent)
  21.           in WrapperComponent
  22.       */
  23.     app = mount(<App/>)
  24.   })
  25.  
  26.   it('renders all blogs it gets from backend', () => {
  27.     console.log("app", app); // => undefined
  28.     app.update()
  29.     const blogComponents = app.find(Blog)
  30.     expect(blogComponents.length).toEqual(blogService.blogs.length)
  31.   })
  32. })
  33.  
  34. /*
  35.     App.js
  36. */
  37. //...
  38. import blogService from './services/blogs'
  39. //...
  40. componentDidMount() {
  41.     console.log("before")               //tulostuu
  42.     blogService.getAll().then(blogs => {
  43.       console.log("Hello, inside?")             //ei tulostu
  44.  
  45.       this.setState({ blogs })
  46.     }).catch (e => {
  47.       console.log("Error in .getAll()", error)       //ei tulostu
  48.     })
  49.     console.log("after .getAll()")              //ei tulostu
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