mocktwit

0.2.0 • Public • Published

Mock testing for projects using twit without calling the Twitter API

Build Status NPM version Dependency Status Code Climate

Installation

Add mocktwit to your devDependencies using npm:

npm install mocktwit --save-dev

Usage

An example using mocha and mockery

var mockery = require('mockery');
var mocktwit = require('mocktwit');
 
describe('twitter', function () {
  before(function () {
    // Inject mocktwit using mockery.
    mockery.enable();
    mockery.registerMock('twit', mocktwit);
  });
 
  it('receives a mock response from twitter API', function () {
    mocktwit.setMockResponse({text: 'hi'});
    // ...
  });
 
  it('spy outgoing requests', function () {
    mocktwit.setRequestListener(function (method, path, params) {
      // ...
    });
    // ...
  });
 
  it('receives mock stream events', function () {
    mocktwit.queueMockStreamEvent('follow', {event: 'follow'});
    mocktwit.queueMockStreamEvent('timeline', {text: 'hello'});
    // ...
  });
 
  afterEach(function () {
    // Clean up.
    mocktwit.cleanup();
  });
 
  after(function () {
    // Disable mocks.
    mockery.disable();
  });
});

Readme

Keywords

none

Package Sidebar

Install

npm i mocktwit

Weekly Downloads

3

Version

0.2.0

License

MIT

Last publish

Collaborators

  • vomitcuddle