Skip to content

Commit

Permalink
refactor(test): Update test code to es6
Browse files Browse the repository at this point in the history
Test code is transpiled on the fly, so it can use es6 code
  • Loading branch information
jcollado committed Feb 2, 2016
1 parent 16df39e commit f8ea7e2
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* global describe it */
'use strict'

const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const sinon = require('sinon')
const sinonChai = require('sinon-chai')
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'

chai.use(chaiAsPromised)
chai.use(sinonChai)
Expand All @@ -13,7 +11,7 @@ const expect = chai.expect

const promisify = require('./src')

describe('promisify', function () {
describe('promisify', () => {
it('calls wrapped function with arguments', function () {
const fn = sinon.stub().yields()
const promisified = promisify(fn)
Expand All @@ -23,35 +21,35 @@ describe('promisify', function () {
})
})

it('rejects when wrapped function returns error', function () {
it('rejects when wrapped function returns error', () => {
const fn = sinon.stub().yields('some error')
const promisified = promisify(fn)
return expect(promisified('some', 'arguments'))
.to.be.eventually.rejectedWith('some error')
})

it('resolves when wrapped function returns no error', function () {
it('resolves when wrapped function returns no error', () => {
const fn = sinon.stub().yields(null, 'a', 'result')
const promisified = promisify(fn)
return expect(promisified('some', 'arguments'))
.to.eventually.be.fulfilled
})

it('resolves single value as such', function () {
it('resolves single value as such', () => {
const fn = sinon.stub().yields(null, 42)
const promisified = promisify(fn)
return expect(promisified('some', 'arguments'))
.to.eventually.deep.equal(42)
})

it('resolves multiple value as an array', function () {
it('resolves multiple value as an array', () => {
const fn = sinon.stub().yields(null, 'a', 'result')
const promisified = promisify(fn)
return expect(promisified('some', 'arguments'))
.to.eventually.deep.equal(['a', 'result'])
})

it('throws when no function is passed', function () {
it('throws when no function is passed', () => {
expect(promisify).to.throw(Error, 'fn parameter must be a function')
})
})

0 comments on commit f8ea7e2

Please sign in to comment.