UNPKG

reactant-module

Version:

A module model for Reactant

53 lines (50 loc) 1.09 kB
import { injectable, createState, createContainer, createStore, action, state, ReactantAction, } from '../..'; test('`createState` with type', () => { @injectable() class Counter { @state count = createState<number, ReactantAction>(($state = 0) => $state); @action increase() { this.count += 1; } } const ServiceIdentifiers = new Map(); const modules = [Counter]; const container = createContainer({ ServiceIdentifiers, modules, options: { defaultScope: 'Singleton', }, }); const counter = container.get(Counter); const store = createStore({ modules, container, ServiceIdentifiers, loadedModules: new Set(), load: (...args: any[]) => {}, dynamicModules: new Map(), pluginHooks: { middleware: [], beforeCombineRootReducers: [], afterCombineRootReducers: [], enhancer: [], preloadedStateHandler: [], afterCreateStore: [], provider: [], }, }); expect(counter.count).toBe(0); counter.increase(); expect(counter.count).toBe(1); });