<commit_before># sinon-stub-promise

This is a little package that makes testing of promises easier when stubbing
with [Sinon.JS](http://sinonjs.org/). This library ensures stubbed promises are
evaluated synchronously, so that no special async tricks are required for
testing.

## Installation

Install with npm: `npm install --save-dev sinon-stub-promise`

In node, you can initialize with sinon:

```javascript
var sinon = require('sinon');
var sinonStubPromise = require('sinon-stub-promise');
sinonStubPromise(sinon);
```

Or in the browser, you can just include
`node_modules/sinon-stub-promise/index.js` (assumes sinon is available on
window object).

## Example

```javascript
// Code under test
function doSomethingWithAPromise(promise, object) {
  promise()
    .then(function(value) {
      // resolves
      object.resolved = value
    })
    .catch(function(value) {
      // rejects
      object.rejected = value
    });
}

// Test

describe('stubbing a promise', function() {
  var promise;

  beforeEach(function() {
    promise = sinon.stubPromise();
  });

  it('can resolve', function() {
    promise.resolves('resolve value')

    var testObject = {};
    doSomethingWithAPromise(promise, testObject);
    expect(testObject.resolved).to.eql('resolve value');
  });

  it('can reject', function() {
    promise.rejects('reject value')

    var testObject = {};
    doSomethingWithAPromise(promise, testObject);
    expect(testObject.rejected).to.eql('reject value');
  });
}
```

## Why?

We wanted a nice synchronous way of stubbing out promises while testing, and<commit_msg>update README for new interface<commit_after># sinon-stub-promise

This is a little package that makes testing of promises easier when stubbing
with [Sinon.JS](http://sinonjs.org/). This library ensures stubbed promises are
evaluated synchronously, so that no special async tricks are required for
testing.

## Installation

Install with npm: `npm install --save-dev sinon-stub-promise`

In node, you can initialize with sinon:

```javascript
var sinon = require('sinon');
var sinonStubPromise = require('sinon-stub-promise');
sinonStubPromise(sinon);
```

Or in the browser, you can just include
`node_modules/sinon-stub-promise/index.js` (assumes sinon is available on
window object).

## Example

```javascript
// Code under test
function doSomethingWithAPromise(promise, object) {
  promise()
    .then(function(value) {
      // resolves
      object.resolved = value
    })
    .catch(function(value) {
      // rejects
      object.rejected = value
    });
}

// Test
describe('stubbing a promise', function() {
  var promise;

  beforeEach(function() {
    promise = sinon.stub().returnsPromise();
  });

  it('can resolve', function() {
    promise.resolves('resolve value')

    var testObject = {};
    doSomethingWithAPromise(promise, testObject);
    expect(testObject.resolved).to.eql('resolve value');
  });

  it('can reject', function() {
    promise.rejects('reject value')

    var testObject = {};
    doSomethingWithAPromise(promise, testObject);
    expect(testObject.rejected).to.eql('reject value');
  });
}
```

## Why?

We wanted a nice synchronous way of stubbing out promises while testing, and
{'fraction_non_alphanumeric': 0.12402859807273858, 'fraction_numerical': 0.0, 'mean_word_length': 3.9891472868217055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2026806', 'n_tokens_mistral': 975, 'n_tokens_neox': 974, 'n_words': 277}