Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
public
src
.gitignore
README.md
package.json
yarn.lock

README.md

How to test the usage of High Order Components

Instead of using hocs directly or composing them with compose/flowRight, we use the createEnhancer helper.

The createEnhancer helper accepts a list describing the hocs that will be applied, this way the hocs are not called on the spot and we can use that list on the test environment to make sure that they are the right ones, on the right order and with the right arguments.

This is how the hocs are used with createEnhancer:

const app = props => (...)

export const enhancer = createEnhancer(
  [withContainer],
  [graphql, "SOME QUERY", "SOME OPTIONS"],
  [withLoading, props => props.data.loading],
  [withProps, props => ({ movies: props.data.results })]
)

export default enhancer(app)

and this is how we can test the enhancer

test("enhancer loads movies from graphql", () => {
  expect(enhancer.description[1].hoc).toBe(graphql)
  expect(enhancer.description[1].args).toEqual([
    "SOME QUERY",
    "SOME OPTIONS"
  ])
})

How to run

yarn // install dependencies
yarn start // run the dev environment
yarn test // run tests
You can’t perform that action at this time.