Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('using a custom injector is reactive', done => {
const user = mobx.observable({ name: 'Noa' });
const mapper = stores => ({ name: stores.user.name });
const DisplayName = props => <h1>{props.name}</h1>;
const User = inject(mapper)(DisplayName);
const App = () => (
);
render(, container);
expect(container.querySelector('h1').textContent).toBe('Noa');
user.name = 'Veria';
expect(container.querySelector('h1').textContent).toBe('Veria');
done();
});
// TODO: fix this!
*/
class TodoView extends Component {
render() {
const { foo } = nullthrows(this.props.apiService);
const { baz } = nullthrows(this.props.todoService);
return (
<p>
{foo}
{baz}
</p>
);
}
}
let Todo = inject('apiService', 'todoService')(observer(TodoView));
// Legacy.
Todo = observer(['apiService', 'todoService'])(TodoView);
Todo = observer(['apiService', 'todoService'], TodoView);
const services = {
apiService: new ApiService(),
todoService: new TodoService()
};
const A = () => (
);
it('component should not be inject', function(done) {
const msg = [];
const baseWarn = console.error;
console.error = m => msg.push(m);
observer(
inject('foo')(
createClass({
render() {
return (
<div>
context:
{this.props.foo}
</div>
);
}
})
)
);
expect(msg.length).toBe(1);
console.error = baseWarn;
done();
it('overriding stores is supported', done => {
const C = inject('foo', 'bar')(
observer(
createClass({
render() {
return (
<div>
context:
{this.props.foo}
{this.props.bar}
</div>
);
}
})
)
);
const B = () => ;
const A = createClass({
it('props override context', done => {
const C = inject('foo')(
createClass({
render() {
return (
<div>
context:
{this.props.foo}
</div>
);
}
})
);
const B = () => ;
const A = createClass({
render: () => (
<b></b>
it('support static hoisting, wrappedComponent and wrappedInstance', done => {
const B = createClass({
render() {
this.testField = 1;
return <div>{this.testField}</div>;
}
});
B.bla = 17;
B.bla2 = {};
const C = inject('booh')(B);
expect(C.wrappedComponent).toBe(B);
expect(B.bla).toBe(17);
expect(C.bla).toBe(17);
let c = null;
render( (c = i)} booh={42} />, container);
expect(c.wrappedInstance.testField).toBe(1);
done();
});
let showView = searchStore['query'] ? 'results' : 'default';
return (
<div>
<a href="#front" id="test-btn">
link
</a>
{showView === 'default' && <div>default</div>}
{showView === 'results' && }
</div>
);
}
}
);
SearchPage = inject('searchStore')(SearchPage);
class SearchResult extends Component {
render() {
return <div>results</div>;
}
}
/**
* Routing
*/
const searchStore = new SearchStore();
const memHistory = createMemoryHistory();
const appRoutes = (