Skip to content

Commit

Permalink
add object support
Browse files Browse the repository at this point in the history
  • Loading branch information
stolenng committed Feb 29, 2020
1 parent 6945053 commit 1b3a9d4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
8 changes: 7 additions & 1 deletion core/wrap-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ const wrapRoot = (wrapperItems: WrapperItems) => {
throw new Error(`${logPrefix} no environment was passed!`);
}

const instance: R = new RootStore();
let instance;

try {
instance = new RootStore();
} catch(e) {
instance = RootStore;
}

if (initFunctionDoesntExists(instance)) {
throw new Error(`${logPrefix} root store must have init function!`);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-easy",
"version": "0.0.8",
"version": "0.0.9",
"description": "Mobx made easier",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
20 changes: 20 additions & 0 deletions tests/wrap-root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ describe('wrapRoot', () => {
});
})

describe('objects', () => {
let fakeObject = {init: jest.fn()}, rootObject;

beforeEach(() => {
rootObject = wrapRoot({
RootStore: fakeObject,
env
});
})

it('should init successfully', () => {
expect(fakeObject.init).toBeCalled();
});

it('should set root and env in wrapperItems', () => {
expect(wrapperItems.values().next().value.root).toEqual(result);
expect(wrapperItems.values().next().value.environmentData).toEqual(env);
});
})

it('should return new root instance with id', () => {
expect(result).toBeInstanceOf(RootStoreWithInit);
});
Expand Down

0 comments on commit 1b3a9d4

Please sign in to comment.