Skip to content

Commit

Permalink
add test case that ensures behavior with unrelated inputs & callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Nick committed Jul 17, 2024
1 parent 0c88070 commit ebfb90c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions exercises/practice/react/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,26 @@ describe('React module', () => {

expect(values).toEqual([])
})

xit('callbacks only fire if related dependencies change', () => {
const [input, setInput] = createInput(1)
const plusOne = createComputed(() => input() + 1)

const [input2, _setInput2] = createInput(10)
const minusOne = createComputed(() => input2() - 1)

const plusOneValues: number[] = []
createCallback(() => plusOneValues.push(plusOne()))
plusOneValues.length = 0 // discard initial values from registration

const minusOneValues: number[] = []
createCallback(() => minusOneValues.push(minusOne()))
minusOneValues.length = 0 // discard initial values from registration

setInput(2)
setInput(3)

expect(plusOneValues).toEqual([3, 4])
expect(minusOneValues).toEqual([])
})
})

0 comments on commit ebfb90c

Please sign in to comment.