0.3.1 • Published 9 years ago

mocha-test-utils v0.3.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

mocha-test-utils

A bunch of helpers to aid mocha testing.

Build Status

check

Use it together with done to simplify error assertion on asynchronous tests.

it('tests something asynchronous', (done) => {
  check(done, function() {
    // asynchronous stuff...
  });
});

mockCreator

Use it to create a module mocker. Handy used with Marty to mock all aspects of a module but one or two things.

// __mocks__/index.js
import ActionCreators from './action-creators';
import Constants from './constants';
import Container from './container';
import Component from './component';
import Store from './store';

export default mockCreator({
  ActionCreators,
  Constants,
  Container,
  Component,
  Store
});

// __tests__/store-test.js
import mockCreator from '../__mocks__';

const mock = mockCreator('actionCreators', 'component');

// Do stuff with:
mock.actionCreators;
mock.component;

propertyDescriptor

Use it to get the propertyDescriptor for specific property on an object. Uses getOwnPropertyDescriptor.

class Foo {
  get property() {}
}

it(`tests a property getter`, () => {
  let pd = propertyDescriptor(Foo, 'property');
  assert(typefo pd.get === 'function', 'has a getter');
});

wcheck

Use it together with done to simplify error assertion on asynchronous tests. It's the same as check but it returns a wrapped function instead. Useful for callbacks.

it('tests something asynchronous', (done) => {
  someCallback(wcheck(done, (arg1) => {
    // asynchronous stuff...
  }));
});

MIT license.

0.3.1

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago