GithubHelp home page GithubHelp logo

react-testing's Introduction

Advanced React

react-testing

  • it
  • ReactDOM.render
  • ReactDOM.unmountComponentAtNode
  • expect - expectation
    • toContain - matcher
    • toEqual - matcher
  • Enzyme uses the naming convention of calling the shallow rendered component as wrapped
  • Types of rendering
    • Static
    • Shallow - shallow
    • Full DOM - mount
  • find()
  • to use absolute path set NODE_PATH in .env. advantage of absolute path is when its easier to move components around without worrying about relative path.
  • beforeEach
  • rem: page reloads on form submit. to prevent reload, call preventDefault in form submit handler.
  • unmount()
  • afterEach - jest
  • simulate
  • update
  • prop
  • describe - jest
  • quick check for redux store
    • App wrapped in Provider (from 'react-redux')
    • set store prop of Provider using createStore
    • createStore takes first arg as combined reducer and second arg is initial state
    • add window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() if dev tools support is needed
  • quick check for using action creators
    • replace component with connect (from 'react-redux')
    • first arg for connect is mapStateToProps callback method (null is not needed)
    • actions
    • actions creator will be available as props
  • use render() over text()
  • render method returns a cheerioWrapper (Cheerio js is similar to jquery)
  • use JSONPlaceholder for fake api data
  • applyMiddleware to apply middleware
  • reduxPromise?
  • moxios
    • install()
    • stubRequest()
    • wait()
    • note: added a 100 to give enough time for moxios to send back the mocked response (Don't do this. just use moxios wait)
    • to make jest wait till the end content of set timeout is executed, use done callback.
  • done() - jest
  • Read more about integration testing

Higher Order Component

  • quick routing
    • BrowserRoute (from 'react-router-dom')
    • Route -> path, component, exact
  • react route
    • this.props.history.push
import React, { Component } from "react";

export default ChildComponent => {
  class ComposedComponent extends Component {
    render() {
      return <ChildComponent {...this.props} />;
    }
  }

  return ComposedComponent;
};
  • when a component is used with higher order component. required actions(when using redux) and history (in case of routes being used) needs to be passed as props. hence using "{...this.props}" in the return.

react-testing's People

Contributors

rr235 avatar

Watchers

 avatar

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.