Skip to content

Commit 4c13d1a

Browse files
committed
test(reactant-module): add testing for defineProperties error
1 parent 30cf632 commit 4c13d1a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

packages/reactant-module/src/core/createStore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ export function createStore<T = any>({
309309
},
310310
});
311311
} catch (e) {
312-
console.error(`${service} has unexpected errors.`);
312+
console.error(
313+
`provide: '${ServiceIdentifier.toString()}' has unexpected errors.`
314+
);
313315
throw e;
314316
}
315317
});

packages/reactant-module/test/index.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,51 @@ test('Unexpected multi-inject: module with multiple module injection with same m
318318
container.get(FooBar);
319319
}).toThrowErrorMatchingSnapshot();
320320
});
321+
322+
test('check defineProperties error', () => {
323+
const options = { foo: 'bar' };
324+
325+
@injectable()
326+
class Todos {
327+
@state
328+
list: string[] = [];
329+
}
330+
331+
const create = () => {
332+
const ServiceIdentifiers = new Map();
333+
const modules = [Todos, { provide: 'options', useValue: options }];
334+
const container = createContainer({
335+
ServiceIdentifiers,
336+
modules,
337+
options: {
338+
defaultScope: 'Singleton',
339+
},
340+
});
341+
container.get(Todos);
342+
createStore({
343+
modules,
344+
container,
345+
ServiceIdentifiers,
346+
loadedModules: new Set(),
347+
load: (...args: any[]) => {
348+
//
349+
},
350+
pluginHooks: {
351+
middleware: [],
352+
beforeCombineRootReducers: [],
353+
afterCombineRootReducers: [],
354+
enhancer: [],
355+
preloadedStateHandler: [],
356+
afterCreateStore: [],
357+
provider: [],
358+
},
359+
});
360+
};
361+
create();
362+
jest.spyOn(global.console, 'error');
363+
364+
expect(create).toThrowError();
365+
expect(console.error).toBeCalledWith(
366+
"provide: 'options' has unexpected errors."
367+
);
368+
});

0 commit comments

Comments
 (0)