Skip to content

Commit

Permalink
Add two edge case tests
Browse files Browse the repository at this point in the history
1.  When unwatch function is called after reactor.reset()
2.  When an observer handler calls unwatch() of an handler queued up to
fire
  • Loading branch information
jordangarcia committed Nov 3, 2015
1 parent e017713 commit 77ced5e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/reactor-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,28 @@ describe('Reactor', () => {
expect(mockFn1.calls.count()).toEqual(2)
expect(mockFn2.calls.count()).toEqual(1)
})
it('should allow a notify() after an unobserve during a handler', () => {
var mockFn1 = jasmine.createSpy()
var mockFn2 = jasmine.createSpy()
var unwatchFn2
var unwatchFn1 = reactor.observe(subtotalGetter, (val) => {
console.log('hanlder1', unwatchFn2)
unwatchFn2()
mockFn1(val)
})

unwatchFn2 = reactor.observe(subtotalGetter, (val) => {
console.log('handler2')
mockFn2(val)
})

expect(function() {
checkoutActions.addItem('foo', 5)
expect(mockFn1.calls.count()).toEqual(1)
expect(mockFn2.calls.count()).toEqual(0)
expect(mockFn1.calls.argsFor(0)).toEqual([5])
}).not.toThrow()
})
})
}) // Reactor with no initial state

Expand Down Expand Up @@ -551,6 +573,16 @@ describe('Reactor', () => {

expect(reactor.evaluateToJS(['persistent'])).toEqual([item])
})

it('should be able to reset and call an unwatch() function without erroring', () => {
const spy = jasmine.createSpy()
const unobserve = reactor.observe(['standard'], () => spy())

reactor.reset()
expect(function() {
unobserve()
}).not.toThrow()
})
})

describe('when a reactor is observing mutable values', () => {
Expand Down

0 comments on commit 77ced5e

Please sign in to comment.