Coder Social home page Coder Social logo

react-async-fetch-lab's Issues

npm test persists the fetchMocks from one run to the next, giving an error on later runs.

Running the test with the watch command - as is used by npm test - persists the fetchMocks from one run to the next, giving an error on later runs.

Error: Adding route with same name as existing route.

  <App />
    1) "before all" hook

  0 passing (1ms)
  1 failing

  1) <App />
       "before all" hook:
     Error: Adding route with same name as existing route. See `overwriteRoutes` option.
      at Object.FetchMock.addRoute (node_modules/fetch-mock/src/lib/set-up-and-tear-down.js:55:9)
      at Object.FetchMock.mock (node_modules/fetch-mock/src/lib/set-up-and-tear-down.js:22:7)
      at Object.FetchMock.(anonymous function) [as get] (node_modules/fetch-mock/src/lib/set-up-and-tear-down.js:98:15)
      at Context.<anonymous> (test/index.test.js:21:15)

test/index.test.js:21 points to fetchMock.get('*', {people: [{name:"Stimpy"}]})

describe('<App />', () => {
  let appWrapper
  let fetchSpy

  before(() => {
    global.fetch = require('node-fetch')
    fetchMock.get('*', {people: [{name:"Stimpy"}]})
    fetchSpy = spy(global, "fetch")
  })
  // ...
})

Functional vs. Container components

The README asks 'App.js' to be written as a functional component, and the next line asks it to include a 'componentDidMount()' method call with a fetch inside. In the solution branch, 'App.js' is a container component, and the call to fetch returns its data to App's state. A student came to me very confused about this today, unsure about where to write 'componentDidMount' inside of a functional component. Some research revealed that one way to do this would be through 'https://www.npmjs.com/package/react-pure-lifecycle,' but the README preceding this lab makes no mention of it.

Additionally, the "Button", "Example", and "Greeting" components aren't used anywhere else in the App.

Tests Don't Test for State or Rendered Output

As far as I can tell, the tests only test for the App component and componentDidMount using fetch. But they aren't testing for anything else, like the code returned from render() or the App constructor() or the declared state inside the constructor.

My code just passed the tests with this code:

import React, {Component} from 'react';

const URL = "http://api.open-notify.org/astros.json"

class App extends Component {

  componentDidMount() {
    fetch(URL).then(res => res.json())
  }

  render() {
    return "hello"
  }
}

export default App;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.