Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
}
render() {
return ;
}
}
const tree = renderToContainer(
);
const target = findRenderedVNodeWithType(tree, Passthrough).children;
const wrapper = findRenderedVNodeWithType(tree, StatefulWrapper).children;
expect(mapStateToPropsCalls).toBe(2);
expect(mapDispatchToPropsCalls).toBe(2);
expect(target.props.statefulValue).toBe('foo');
// Impure update
const storeGetter = wrapper.state.storeGetter;
storeGetter.storeKey = 'bar';
wrapper.setState({ storeGetter });
expect(mapStateToPropsCalls).toBe(3);
expect(mapDispatchToPropsCalls).toBe(3);
expect(target.props.statefulValue).toBe('bar');
});
() => ({ scooby: 'boo' })
)(
class ContainerNext extends Component {
render() {
return ;
}
}
);
const tree = renderToContainer(
);
const container = findRenderedVNodeWithType(tree, ContainerBefore).children;
const stub = findRenderedVNodeWithType(tree, Passthrough).children;
expect(stub.props.foo).toBeUndefined();
expect(stub.props.scooby).toBe('doo');
const imitateHotReloading = (TargetClass, SourceClass) => {
// Crude imitation of hot reloading that does the job
Object.getOwnPropertyNames(SourceClass.prototype)
.filter(key => typeof SourceClass.prototype[key] === 'function')
.forEach(key => {
if (key !== 'render' && key !== 'constructor') {
TargetClass.prototype[key] = SourceClass.prototype[key];
}
});
container.forceUpdate();
};
it('should add the store to the child context', () => {
const store1 = createStore(() => ({}));
const store2 = createStore(() => ({}));
const spy = spyOn(console, 'error');
let tree = renderIntoContainer(createElement(Provider, { store: store1 }, createElement(Child, {})));
expect(spy.calls.count()).toEqual(0);
let child = findRenderedVNodeWithType(tree, Child).children;
expect(child.context.store).toBe(store1);
tree = renderIntoContainer(createElement(Provider, { store: store1 }, createElement(Provider, { store: store2 }, createElement(Child, {}))));
expect(spy.calls.count()).toEqual(0);
child = findRenderedVNodeWithType(tree, Child).children;
expect(child.context.store).toBe(store2);
});
it('Should work with Synthetic events', () => {
const testObj = {
clicker: () => {}
};
const sinonSpy = sinon.spy(testObj, 'clicker');
class FooBar extends Component {
render() {
return <div>Test</div>;
}
}
const tree = renderIntoDocument();
const vnode = findRenderedVNodeWithType(tree, 'div');
vnode.dom.click();
expect(sinonSpy.callCount).toEqual(1);
});
);
const vNode = (
);
const tree = renderToContainer(vNode);
const stub = findRenderedVNodeWithType(tree, Passthrough).children;
expect(stub.props.dispatch).toBe(store.dispatch);
expect(stub.props.foo).toBeUndefined();
expect(stub.props.pass).toBe('through');
expect(() => findRenderedVNodeWithType(tree, Container).children).not.toThrowError();
const decorated = findRenderedVNodeWithType(tree, Container).children;
expect(decorated.isSubscribed()).toBe(false);
};
return ;
}
}
renderToContainer(
{
container = instance;
}}
/>
);
const propsBefore = {
...findRenderedVNodeWithType(container, Passthrough).children.props
};
props = {};
container.forceUpdate();
const propsAfter = {
...findRenderedVNodeWithType(container, Passthrough).children.props
};
expect(propsBefore.x).toBe(true);
expect('x' in propsAfter).toBe(false);
});
this.setState({
bar
});
}
render() {
return (
);
}
}
const tree = renderToContainer();
const stub = findRenderedVNodeWithType(tree, Passthrough).children;
expect(stub.props.foo).toBe('bar');
expect(stub.props.pass).toBe('');
});
class Container extends Component {
render() {
return ;
}
}
const decorator = connect(state => state);
const Decorated = decorator(Container);
const tree = renderToContainer(
);
const decorated = findRenderedVNodeWithType(tree, Decorated).children;
expect(() => decorated.getWrappedInstance()).toThrowError(
/To access the wrapped instance, you need to specify \{ withRef: true \} in the options argument of the connect\(\) call\./
);
});
constructor() {
super();
this.state = { extra: 'z' };
}
render() {
return (
);
}
}
const outerStub = render(, document.createElement('div'));
const stub = findRenderedVNodeWithType(outerStub, Passthrough).children;
expect(stub.props.stateThing).toBe('');
stub.props.mergedDoSomething('a');
outerStub.setState({}, () => {
expect(stub.props.stateThing).toBe('HELLO az');
stub.props.mergedDoSomething('b');
outerStub.setState({}, () => {
expect(stub.props.stateThing).toBe('HELLO azbz');
outerStub.setState({ extra: 'Z' });
outerStub.setState({}, () => {
stub.props.mergedDoSomething('c');
outerStub.setState({}, () => {
expect(stub.props.stateThing).toBe('HELLO azbzcZ');
done();
super(props);
this.state = { pass: '' };
}
render() {
return (
);
}
}
const vNode = ;
const rootStub = renderToContainer(vNode);
const stub = findRenderedVNodeWithType(rootStub, Passthrough).children;
expect(renderCallCount).toBe(1);
expect(stub.props.string).toBe('');
expect(stub.props.pass).toBe('');
store.dispatch({ type: 'APPEND', payload: 'a' });
renderToContainer(vNode);
expect(renderCallCount).toBe(2);
expect(stub.props.string).toBe('a');
expect(stub.props.pass).toBe('');
rootStub.setState({ pass: '' });
renderToContainer(vNode);
expect(renderCallCount).toBe(2);
expect(stub.props.string).toBe('a');
expect(stub.props.pass).toBe('');