'use babel'

import promisify from '..'

describe('Promisify', function() {
  it('succeeds properly', function() {
    const callback = function(arg1, arg2) {
      expect(arg1).toBe('something')
      arg2(null, 'wow')
    }
    waitsForPromise(function() {
      return promisify(callback)('something').then(function(retVal) {
        expect(retVal).toBe(retVal)
      })
    })
  })

  it('throws properly', function() {
    const callback = function(arg1, arg2) {
      expect(arg1).toBe('something')
      arg2('wow')
    }
    waitsForPromise(function() {
      return promisify(callback)('something').then(function() {
        expect(false).toBe(true)
      }, function(error) {
        expect(error).toBe('wow')
      })
    })
  })
  it('works when Array.from is available', function() {
    const _ = Array.from
    Array.from = function(array) {
      return Array.prototype.slice.call(array)
    }
    const callback = function(arg1, arg2) {
      expect(arg1).toBe('something')
      arg2(null, 'wow')
    }
    waitsForPromise(function() {
      return promisify(callback)('something').then(function(retVal) {
        expect(retVal).toBe(retVal)
        Array.from = _
      })
    })
  })
  it('works when Array.from is not available', function() {
    const _ = Array.from
    Array.from = null
    const callback = function(arg1, arg2) {
      expect(arg1).toBe('something')
      arg2(null, 'wow')
    }
    waitsForPromise(function() {
      return promisify(callback)('something').then(function(retVal) {
        expect(retVal).toBe(retVal)
        Array.from = _
      })
    })
  })
})

@@ -1598,11 +1598,524 @@
 %7D)%0A  %7D)%0A
+  it('has an option to disable the throw behavior', function() %7B%0A    function callback(beep, callback) %7B%0A      if (beep === true) %7B%0A        callback(null, true)%0A      %7D%0A      throw new Error('Hello')%0A    %7D%0A    waitsForPromise(function() %7B%0A      return promisify(callback, false)(true).then(function(result) %7B%0A        expect(result).toBe(true)%0A      %7D)%0A    %7D)%0A    waitsForPromise(function() %7B%0A      return promisify(callback, false)().then(function(result) %7B%0A        expect(result).toBe(null)%0A      %7D)%0A    %7D)%0A  %7D)%0A
 %7D)%0A

Add specs for change