Skip to content

Instantly share code, notes, and snippets.

@Jnforja
Created July 21, 2020 18:39
Show Gist options
  • Save Jnforja/432959e680f936c7b0f3359484b76365 to your computer and use it in GitHub Desktop.
Save Jnforja/432959e680f936c7b0f3359484b76365 to your computer and use it in GitHub Desktop.
import React from "react"
import { render } from "@testing-library/react"
test("Adds number and gives result as a prop", function test() {
let result
function WrappedComponent({ sum }) {
result = sum
return null
}
const ComponentWithSum = withSum(WrappedComponent, [4, 6])
render(<ComponentWithSum />)
expect(result).toBe(10)
})
function withSum(WrappedComponent, numbersToSum) {
const sum = numbersToSum.reduce((a, b) => a + b, 0)
return () => <WrappedComponent sum={sum} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment