daily pastebin goal
19%
SHARE
TWEET

Untitled

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