0.4.0 • Published 8 years ago

chai-sync-layer-suite v0.4.0

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

chai-sync-layer-suite

Set of Chai matchers and helpers that simplifies process of testing sync layer (TODO wtf is sync layer).

Installation

Install via npm:

npm install --save-dev chai-sync-layer-suite

Then require it in your test helper:

// Matchers:
var syncMatchers = require('chai-sync-layer-suite/src/sync_matchers');
chai.use(syncMatchers);

// Describe helper
var describeSync = require('chai-sync-layer-suite/src/describe_sync');
window.describeSync = describeSync; // Export to global scope (window for Karma)

Usage

Real life usage example:

invitations_sync.js:

var requests = require('stores/requests');

var invitationsSync = {
  get: function(token) {
    return requests.get('/invitations/' + token);
  },

  create: function(projectId, payload) {
    return requests.signedPost(
      '/projects/' + projectId + '/invitations', payload
    );
  },

  delete: function(token) {
    return requests.signedDelete('/invitations/' + token);
  },

  accept: function(token) {
    return requests.signedPut('/invitations/' + token);
  }
};

module.exports = invitationsSync;

invitations_sync_test.js:

var invitationsSync = rewire('../invitations_sync');

describeSync('invitationsSync', invitationsSync, function() {
  it('get', function() {
    expect(invitationsSync.get.with('zaq1xsw2')).to.perform.request(
      'get', '/invitations/zaq1xsw2'
    );
  });

  it('create', function() {
    expect(invitationsSync.create.with(42, { a: 'A' })).to.perform.request(
      'signedPost', '/projects/42/invitations', { a: 'A' }
    );
  });

  it('delete', function() {
    expect(invitationsSync.delete.with('zaq1xsw2')).to.perform.request(
      'signedDelete', '/invitations/zaq1xsw2'
    );
  });

  it('accept', function() {
    expect(invitationsSync.accept.with('zaq1xsw2')).to.perform.request(
      'signedPut', '/invitations/zaq1xsw2'
    );
  });
});

Tests

npm test

For watch mode:

npm run-script autotest

Roadmap

  • More docs
  • Simpler describeSync API
  • Matchers and helpers for rest parts of sync layer

--

License (MIT)

0.4.0

8 years ago

0.3.0

8 years ago

0.2.0

9 years ago

0.1.0

9 years ago