Skip to content

Commit

Permalink
chore: add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn committed Dec 2, 2024
1 parent 7a66f8d commit 632ba17
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/store/tests/derived.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,34 @@ describe('Derived', () => {
expect(halfDouble.state).toBe(24)
})


test('should be able to mount in the wrong order and still work with a derived and a non-derived state', () => {
const count = new Store(12)

const double = new Derived({
deps: [count],
fn: () => {
return count.state * 2
},
})

const countPlusDouble = new Derived({
deps: [count, double],
fn: () => {
return count.state + double.state
},
})

countPlusDouble.mount()
double.mount()

count.setState(() => 24)

expect(count.state).toBe(24)
expect(double.state).toBe(48)
expect(countPlusDouble.state).toBe(24 + 48)
})

test('should recompute in the right order', () => {
const count = new Store(12)

Expand Down

0 comments on commit 632ba17

Please sign in to comment.