import Microcosm  from '../src/Microcosm'
import assert     from 'assert'
import eventually from '../src/eventually'

describe('When working with promises', function() {

  beforeEach(function(done) {
    this.app = new Microcosm()
    this.originalThrow = eventually.throws
    this.app.start(done)
  })

  afterEach(function() {
    eventually.throws = this.originalThrow
  })

  context('and a store handler raises an exception', function() {
    let action = () => Promise.resolve(true)
    let error  = new Error('Promise trapped error during dispatch!')

    beforeEach(function() {
      this.app.addStore({
        register() {
          return {
            [action] : () => { throw error }
          }
        }
      })
    })

    it ('does not trap errors raised in that store handler', function (done) {
      eventually.throws = function (exception) {
        assert.equal(exception, error)
        done()
      }

      this.app.push(action)
    })
  })
})

@@ -610,33 +610,21 @@
 ore(
-%7B%0A        register
+function
 () %7B%0A
-  
     
@@ -650,18 +650,16 @@
     
-  
 %5Baction%5D
  : (
@@ -654,17 +654,16 @@
 %5Baction%5D
- 
 : () =%3E 
@@ -682,20 +682,8 @@
 r %7D%0A
-          %7D%0A
     

Use function syntax for clarity in promise-test