Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including bitbox-mock with all npm packages installed. Try it out:

var bitboxMock = require("bitbox-mock")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

bitbox-mock v1.0.3

A mocking library for BITBOX, used in unit tests for apps that depend on BITBOX.

bitbox-mock

Greenkeeper badge

This is a mocking library for BITBOX JavaScript SDK. If you write an app that depends on the BITBOX library, you can use this mocking library to write unit tests.

Unit tests should not call external services. That's the primary difference between unit tests and integration tests. Instead of making live calls with BITBOX, this mocking library can be used instead.

Usage

In a normal app, you would instantiate BITBOX accordingly:

const BITBOXSDK = require('bitbox-sdk')
const BITBOX = new BITBOXSDK()

const result = BITBOX.Address.details(someBCHAddr)

In your unit tests, you can use this mocking library to replace the BITBOX object like so:

const BITBOX = require('bitbox-mock')

const result = BITBOX.Address.details(someBCHAddr)

This mocking library depends on Sinon for mocking. If you want to mock a specific data set, you can override the default return values like this:

const sinon = require('sinon')
const BITBOX = require('bitbox-mock')

// This is an example of your own mocked data.
const myMockData = {
  balance: 0.324,
  cashAddress: 'bchtest:qzsfqeqtdk6plsvglccadkqtf0trf2nyz58090e6tt'
}

BITBOX.Address.details = sinon.stub().returns(myMockData)

const result = BITBOX.Address.details(someBCHAddr)
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free