Skip to content

Commit

Permalink
fix: Make withInjectables have access to all features of di
Browse files Browse the repository at this point in the history
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
  • Loading branch information
Iku-turso and jansav committed Mar 14, 2024
1 parent df4b9c1 commit 543dc16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export default (Component, { getPlaceholder = constant(null), getProps }) =>
};

const diForComponentContext = {
...di,

inject: (alias, parameter) =>
di.inject(alias, parameter, componentContext),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import asyncFn from '@async-fn/jest';
import { observable, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import registerInjectableReact from '../registerInjectableReact/registerInjectableReact';
import { keys } from 'lodash/fp';

const flushPromises = () => new Promise(flushMicroTasks);

Expand Down Expand Up @@ -166,6 +167,23 @@ describe('withInjectables', () => {
expect(rendered.baseElement).toMatchSnapshot();
});

it('given component, when rendered, has access to full di from react context', () => {
const DumbTestComponent = () => <div />;

const SmartTestComponent = withInjectables(DumbTestComponent, {
getProps: diInGetProps => {
expect(keys(diInGetProps)).toEqual(keys(di));
expect(keys(diInGetProps)).not.toEqual([]);

return {};
},
});

mount(<SmartTestComponent />);

expect.assertions(2);
});

[
{
name: 'given anonymous component and a dependency cycle, when rendered, throws context for a uniquely generated component name and cycle',
Expand Down

0 comments on commit 543dc16

Please sign in to comment.