A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/setContext.html below:

setContext(context) ยท Enzyme

.setContext(context) => Self

A method that sets the context of the root component, and re-renders. Useful for when you are wanting to test how the component behaves over time with changing contexts.

NOTE: can only be called on a wrapper instance that is also the root instance.

Arguments
  1. context (Object): An object containing new props to merge in with the current state
Returns

ReactWrapper: Returns itself.

Example
import React from 'react';
import PropTypes from 'prop-types';

function SimpleComponent(props, context) {
  const { name } = context;
  return <div>{name}</div>;
}
SimpleComponent.contextTypes = {
  name: PropTypes.string,
};
const context = { name: 'foo' };
const wrapper = mount(<SimpleComponent />, { context });
expect(wrapper.text()).to.equal('foo');
wrapper.setContext({ name: 'bar' });
expect(wrapper.text()).to.equal('bar');
wrapper.setContext({ name: 'baz' });
expect(wrapper.text()).to.equal('baz');
Common Gotchas

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4