Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfisher committed Jun 30, 2024
1 parent c453879 commit a169fce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/reactive/src/__tests__/async/funcs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ describe("异步计算控制功能",()=>{
store.state.total
})
})
test("当执行计算函数重试5次过程中读取retry值",()=>{
let count = 0
let times:number[] = []
let retryValues:(number|undefined)[] = []
return new Promise<void>((resolve)=>{
const store = createStore({
price:2,
count:3,
total:computed(async (_,{})=>{
throw new Error("error")
},['price','count'],{id:'x',retry:[5,100]})
},{onceComputed:true})
store.watch((valuePath)=>{
retryValues.push(store.state.total.retry)
if(retryValues.length===5){
expect(retryValues).toEqual([5,4,3,2,1,0])
resolve()
}
},['total'])
})
},0)



Expand Down
2 changes: 1 addition & 1 deletion packages/reactive/src/watch/createWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function createWatch<T extends StoreDefine>(store:IStore<T>){
const valuePaths:string[][] = triggerReasons.map((reason:any)=>reason.keyPath)
listener(valuePaths)
},()=>{
return depends?.map(dep=>getValueByPath(store.stateCtx.state,dep))
return depends?.map(dep=>getValueByPath(store.state,dep))
})
return unwatch
}
Expand Down

0 comments on commit a169fce

Please sign in to comment.