require('reify')

const expect = require('chai').expect
const observer = require('../src')

describe('unobserve', () => {
  it('should unobserve the observed function', () => {
    let dummy
    const observable = observer.observable({prop: 0})

    let numOfRuns = 0
    function test() {
      dummy = observable.prop
      numOfRuns++
    }
    const signal = observer.observe(test)

    return Promise.resolve()
      .then(() => observable.prop = 'Hello')
      .then(() => observer.unobserve(signal))
      .then(() => observable.prop = 'World')
      .then(() => observable.prop = '!')
      .then(() => expect(numOfRuns).to.equal(2))
  })

  it('should unobserve when the same key is used multiple times', () => {
    let dummy
    const observable = observer.observable({prop: { prop: '' } })

    let numOfRuns = 0
    function test() {
      dummy = observable.prop.prop
      numOfRuns++
    }
    const signal = observer.observe(test)

    return Promise.resolve()
      .then(() => observable.prop.prop = 'Hello')
      .then(() => observer.unobserve(signal))
      .then(() => observable.prop.prop = 'World')
      .then(() => observable.prop.prop = '!')
      .then(() => expect(numOfRuns).to.equal(2))
  })

  it('should unobserve even if the function is registered for the stack', () => {
    let dummy
    const observable = observer.observable({prop: 0})

    let numOfRuns = 0
    function test() {
      dummy = observable.prop
      numOfRuns++
    }
    const signal = observer.observe(test)

    return Promise.resolve()
      .then(() => {
        observable.prop = 2
        observer.unobserve(signal)
      })
      .then(() => expect(numOfRuns).to.equal(1))
  })
})

@@ -1210,32 +1210,596 @@
 equal(2))%0A  %7D)%0A%0A
+  it('should unobserve multiple observers for the same target and key', () =%3E %7B%0A    let dummy%0A    const observable = observer.observable(%7B ctr: 0 %7D)%0A%0A    const signal1 = observer.observe(() =%3E dummy = observable.ctr)%0A    const signal2 = observer.observe(() =%3E dummy = observable.ctr)%0A    const signal3 = observer.observe(() =%3E dummy = observable.ctr)%0A    observer.unobserve(signal1)%0A    observer.unobserve(signal2)%0A    observer.unobserve(signal3)%0A%0A    return Promise.resolve()%0A      .then(() =%3E observable.ctr++)%0A      .then(() =%3E expect(dummy).to.equal(0))%0A  %7D)%0A%0A
   it('should uno

test multiple observer unobserve