Skip to content

Commit 77ced5e

Browse files
committed
Add two edge case tests
1. When unwatch function is called after reactor.reset() 2. When an observer handler calls unwatch() of an handler queued up to fire
1 parent e017713 commit 77ced5e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/reactor-tests.js

+32
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,28 @@ describe('Reactor', () => {
482482
expect(mockFn1.calls.count()).toEqual(2)
483483
expect(mockFn2.calls.count()).toEqual(1)
484484
})
485+
it('should allow a notify() after an unobserve during a handler', () => {
486+
var mockFn1 = jasmine.createSpy()
487+
var mockFn2 = jasmine.createSpy()
488+
var unwatchFn2
489+
var unwatchFn1 = reactor.observe(subtotalGetter, (val) => {
490+
console.log('hanlder1', unwatchFn2)
491+
unwatchFn2()
492+
mockFn1(val)
493+
})
494+
495+
unwatchFn2 = reactor.observe(subtotalGetter, (val) => {
496+
console.log('handler2')
497+
mockFn2(val)
498+
})
499+
500+
expect(function() {
501+
checkoutActions.addItem('foo', 5)
502+
expect(mockFn1.calls.count()).toEqual(1)
503+
expect(mockFn2.calls.count()).toEqual(0)
504+
expect(mockFn1.calls.argsFor(0)).toEqual([5])
505+
}).not.toThrow()
506+
})
485507
})
486508
}) // Reactor with no initial state
487509

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

552574
expect(reactor.evaluateToJS(['persistent'])).toEqual([item])
553575
})
576+
577+
it('should be able to reset and call an unwatch() function without erroring', () => {
578+
const spy = jasmine.createSpy()
579+
const unobserve = reactor.observe(['standard'], () => spy())
580+
581+
reactor.reset()
582+
expect(function() {
583+
unobserve()
584+
}).not.toThrow()
585+
})
554586
})
555587

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

0 commit comments

Comments
 (0)