<commit_before># nisemono

[![Build Status](https://travis-ci.org/kumabook/nisemono.svg?branch=master)](https://travis-ci.org/kumabook/nisemono) [![Coverage Status](https://coveralls.io/repos/github/kumabook/nisemono/badge.svg?branch=master)](https://coveralls.io/github/kumabook/nisemono?branch=master) [![Code Climate](https://codeclimate.com/github/kumabook/nisemono/badges/gpa.svg)](https://codeclimate.com/github/kumabook/nisemono)

Simple and thin test double library.

## How to use

### args and returns

```js

var nisemono = require('nisemono');
var sum      = nisemono.func();

sum.expects()
    .withArgs(1, 2, 3)
    .returns(6);

var v = sum(1, 2, 3);
assert(v === 6);

```

### throws

```js

var nisemono = require('nisemono');
var sum      = nisemono.func();

sum.expects()
    .withArgs('one')
    .throws(new Error('bad argument'));

sum('one'); // throw error

```

### callback


```js

var nisemono = require('nisemono');
var fetch    = nisemono.func();

fetch.onCall(function() {
  fetch.callArgFuncAt(2, ['entry1', 'entry2', 'entry3']);
  // or
  fetch.callArgFuncAt(3, new Error('network error'));
});

fetch('GET', 'http://www.example.com/entries', function(entries) {
  assert(entries.length === 3);
  assert(entries[0] === 'entry1');
}, function(e) {
  assert(e.message === 'network error');
});

```

## LICENSE

MIT License

Copyright (c) 2017 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<commit_msg>Update README.md: `callback` and `Promise` sections<commit_after># nisemono

[![Build Status](https://travis-ci.org/kumabook/nisemono.svg?branch=master)](https://travis-ci.org/kumabook/nisemono) [![Coverage Status](https://coveralls.io/repos/github/kumabook/nisemono/badge.svg?branch=master)](https://coveralls.io/github/kumabook/nisemono?branch=master) [![Code Climate](https://codeclimate.com/github/kumabook/nisemono/badges/gpa.svg)](https://codeclimate.com/github/kumabook/nisemono)

Simple and thin test double library.

## How to use

### args and returns

```js

var nisemono = require('nisemono');
var sum      = nisemono.func();

sum.expects()
   .withArgs(1, 2, 3)
   .returns(6);

var v = sum(1, 2, 3);
assert(v === 6);

```

### throws

```js

var nisemono = require('nisemono');
var sum      = nisemono.func();

sum.expects()
   .withArgs('one')
   .throws(new Error('bad argument'));

sum('one'); // throw error

```

### callback


```js

var nisemono = require('nisemono');
var fetch    = nisemono.func();

fetch.expects().calls(function() {
  fetch.callArgFuncAt(2, ['entry1', 'entry2', 'entry3']);
  // or
  fetch.callArgFuncAt(3, new Error('network error'));
});

fetch('GET', 'http://www.example.com/entries', function(entries) {
  assert(entries.length === 3);
  assert(entries[0] === 'entry1');
}, function(e) {
  assert(e.message === 'network error');
});

```

### Promise

```
var nisemono = require('nisemono');
var fetch    = nisemono.func();

fetch.expects().resolves(new Error('network error'));

fetch('GET', 'http://www.example.com/entries').then(function(entries) {
  assert(entries.length === 3);
  assert(entries[0] === 'entry1');
});

```

```
var nisemono = require('nisemono');
var fetch    = nisemono.func();

fetch.expects().rejects(['entry1', 'entry2', 'entry3']);

fetch('GET', 'http://www.example.com/entries').then(function(e) {
  assert(e.message === 'network error');
});

```

## LICENSE

MIT License

Copyright (c) 2017 <NAME>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
{'fraction_non_alphanumeric': 0.18748429253581303, 'fraction_numerical': 0.011560693641618497, 'mean_word_length': 4.827232796486091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 12, 'lorem ipsum': 0, 'www.': 4, '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': '581186', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1366, 'n_words': 304}