Skip to content
Myr

test(ts): some more test cases

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by Alec Larson · parent acf8a57 · Browse files · 1 file+72 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+72 added−2 removed

  • tests:+72 added−2 removed

1 file+72 added−2 removed

modified:__tests__/produce.ts+72 added-2 removed
77 unmodified lines
78})7980it("can infer state type from recipe function", () => {81 type State = {readonly a: string} | {readonly b: string}82 type Recipe = (base: State) => State82 type Recipe = (base: State, n: number) => State8384 let foo = produce((draft: Draft<State>) => {})84 let foo = produce((draft: Draft<State>, number: number) => {})85 exactType(foo, {} as Recipe)86 const state: State = foo({} as State, 3)87})8889it("can infer state type from recipe function with arguments", () => {90 type State = {readonly a: string} | {readonly b: string}
218 unmodified lines
309 let val: {readonly a: ReadonlyArray<number>} = 0 as any310 let arr: ReadonlyArray<typeof val> = 0 as any311 insert(arr, 0, val)312})313314it("can work with non-readonly base types", () => {315 const state = {316 price: 10,317 todos: [318 {319 title: "test",320 done: false321 }322 ]323 }324 type State = typeof state325326 const newState: State = produce(state, draft => {327 draft.price += 5328 draft.todos.push({329 title: "hi",330 done: true331 })332 })333334 const reducer = (draft: State) => {335 draft.price += 5336 draft.todos.push({337 title: "hi",338 done: true339 })340 }341 const newState2: Immutable<State> = produce(reducer)(state)342 const newState3: Immutable<State> = produce(reducer, state)()343})344345it("can work with readonly base types", () => {346 type State = {347 readonly price: number348 readonly todos: readonly {349 readonly title: string350 readonly done: boolean351 }[]352 }353354 const state: State = {355 price: 10,356 todos: [357 {358 title: "test",359 done: false360 }361 ]362 }363364 const newState: State = produce(state, draft => {365 draft.price + 5366 draft.todos.push({367 title: "hi",368 done: true369 })370 })371372 const reducer = (draft: Draft<State>) => {373 draft.price += 5374 draft.todos.push({375 title: "hi",376 done: true377 })378 }379 const newState2: State = produce(reducer)(state)380 const newState3: State = produce(reducer, state)()381})