-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fallback): add fallback logic and error hint for invalid model (#…
…144) * feat(fallback): add fallback logic and error hint for invalid model * test(coverage): add testcase to improve test coverage
- Loading branch information
1 parent
f347240
commit a217007
Showing
6 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// <reference path="../index.d.ts" /> | ||
import { renderHook } from '@testing-library/react-hooks' | ||
// @ts-ignore | ||
import { ErrorModel as EM } from './errorModel' | ||
import { Model } from '../../src' | ||
|
||
describe('useStore', () => { | ||
test('create by single model error definition', async () => { | ||
let state: any | ||
let actions: any | ||
let count = 0 | ||
const ErrorModel = Model(EM) | ||
// @ts-ignore | ||
const { useStore, subscribe, unsubscribe } = Model({ ErrorModel }) | ||
renderHook(() => { | ||
;[state, actions] = useStore('ErrorModel') | ||
}) | ||
expect(actions).toEqual({}) | ||
expect(actions.increment).toBe(undefined) | ||
// await actions.increment(3) | ||
expect(state).toEqual({}) | ||
// test subscribe | ||
// @ts-ignore | ||
subscribe('increment', () => (count += 1)) | ||
expect(count).toBe(0) | ||
expect(state.count).toBe(undefined) | ||
// test unsubscribe | ||
// @ts-ignore | ||
unsubscribe('increment') | ||
expect(actions).toEqual({}) | ||
expect(state.count).toBe(undefined) | ||
expect(count).toBe(0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/// <reference path="../index.d.ts" /> | ||
import { renderHook } from '@testing-library/react-hooks' | ||
// @ts-ignore | ||
import { ErrorModel } from './errorModel' | ||
import { Model } from '../../src' | ||
|
||
describe('useStore', () => { | ||
test('create by single model definition', async () => { | ||
let state: any | ||
let actions: any | ||
let count = 0 | ||
// @ts-ignore | ||
const { useStore, subscribe, unsubscribe } = Model(ErrorModel) | ||
renderHook(() => { | ||
;[state, actions] = useStore() | ||
}) | ||
expect(state).toEqual({}) | ||
expect(actions.increment).toBe(undefined) | ||
// await actions.increment(3) | ||
expect(state).toEqual({}) | ||
// test subscribe | ||
subscribe('increment', () => (count += 1)) | ||
expect(actions).toEqual({}) | ||
expect(count).toBe(0) | ||
expect(state.count).toBe(undefined) | ||
// test unsubscribe | ||
unsubscribe('increment') | ||
expect(actions).toEqual({}) | ||
expect(state.count).toBe(undefined) | ||
expect(count).toBe(0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Use to simulate a error model.js file | ||
export const ErrorModel: any = { | ||
actions: { | ||
// @ts-ignore | ||
add: (params, { state }) => { | ||
return { | ||
count: state.count + params | ||
} | ||
}, | ||
// @ts-ignore | ||
addCaller: (_, { actions }) => { | ||
actions.add(5) | ||
}, | ||
// @ts-ignore | ||
increment: params => { | ||
// @ts-ignore | ||
return state => { | ||
state.count += params | ||
} | ||
}, | ||
state: { count: 0 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters