
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
react-test-context-provider
Advanced tools
A function that allows you to specify context to pass to a child component (intended for testing only)
A function that allows you to specify context to pass to a child component (intended for testing only).
This module is distributed via npm which is bundled with node and should
be installed as one of your project's devDependencies:
npm install --save-dev react-test-context-provider
var getContextProvider = require('react-test-context-provider')
var contextObject = {color: 'blue'} // the context you want to provide to the children components
var reactElement = getElementWithContext(contextObject, <ComponentThatNeedsContext />) // returns the react element as rendered with the given context
In this example, I'm using the Jest testing framework.
Button.js
import React, {PropTypes} from 'react'
export default function Button({children}, {color}) {
// function components receive context as the second argument
return <button style={{background: color}}>{children}</button>
}
Button.propTypes = {children: PropTypes.any.isRequired}
Button.contextTypes = {color: PropTypes.string}
Button.test.js
import React from 'react'
import renderer from 'react-test-renderer'
import getElementWithContext from 'react-test-context-provider'
import Button from './Button'
test('styles the button with a background of the context color', () => {
const element = getElementWithContext({color: 'blue'}, <Button>Click Me</Button>)
const component = renderer.create(element)
expect(component).toMatchSnapshot()
// NOTE: This API is also curried, so you can provide the context first and the children later:
// import getContextProvider from 'react-test-context-provider'
// const getElementWithBlueColorContext = getContextProvider({color: 'blue'})
// const element = getElementWithBlueColorContext(<Button>Click Me</Button>)
})
MIT
FAQs
A function that allows you to specify context to pass to a child component (intended for testing only)
The npm package react-test-context-provider receives a total of 1,146 weekly downloads. As such, react-test-context-provider popularity was classified as popular.
We found that react-test-context-provider demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.