Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('parent component only gets its own context', () => {
const p = renderAndFind(UIChildWithOwnStateJSX, Parent);
assert(shallowEqual(p.props.ui, uiState), 'parent only has its own context and not childrens');
});
it('child merges parent UI context with its own UI context', () => {
const child = renderAndFind(UIChildWithOwnStateJSX, Child);
const expectedState = {
name: 'parent',
child: true
};
assert(shallowEqual(child.props.ui, expectedState), 'child merges context');
});
it('components with the same key and nesting share the same context', () => {
const tree = render(<div></div>);
const a = ReactTestUtils.findRenderedComponentWithType(tree, Foo);
const b = ReactTestUtils.findRenderedComponentWithType(tree, Bar);
assert(shallowEqual(a.props.ui, b.props.ui));
a.updateContext();
assert(a.props.ui.name === 'misc');
assert(shallowEqual(a.props.ui, b.props.ui));
});
const dispatchValidate = value => {
const fieldValidity = getValidity(props.validators, value);
const fieldErrors = getValidity(props.errors, value);
const errors = props.validators
? merge(invertValidity(fieldValidity), fieldErrors)
: fieldErrors;
if (fieldValue && !shallowEqual(errors, fieldValue.errors)) {
dispatch(setErrors(model, errors));
}
return value;
};
componentWillReceiveProps(nextProps: Props) {
const params = extractWatchedProps(watchProps, this.props);
const nextParams = extractWatchedProps(watchProps, nextProps);
if (!shallowEqual(params, nextParams)) {
this.fetchData(nextParams, nextProps);
}
}
componentDidUpdate (prevProps) {
const params = mapParams(paramKeys, this.props.params)
const prevParams = mapParams(paramKeys, prevProps.params)
if (!shallowEqual(params, prevParams))
fn(params, this.props.actions)
}
componentWillReceiveProps (nextProps) {
if (!shallowEqual(this.props.params, nextProps.params))
this.setState({
usernameOrRepo: parseFullName(nextProps.params)
})
}
shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(nextProps, this.props);
}