Skip to content

Commit

Permalink
added randomness to the tests by using chance directly
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed May 31, 2016
1 parent 3b0174e commit cd358cf
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions test/unit/any-test.js
@@ -1,84 +1,70 @@
import proxyquire from 'proxyquire';
import sinon from 'sinon';
import {assert} from 'chai';
import Chance from 'chance';

var chanceStub = {
bool: () => undefined,
date: () => undefined,
email: () => undefined,
natural: () => undefined,
string: () => undefined,
url: () => undefined,
word: () => undefined
};

const any = proxyquire('../../any', {
chance: sinon.stub().returns(chanceStub)
});
const chance = new Chance();

suite('random data generator', () => {
let sandbox;
let sandbox, any, chanceStub;
const options = {foo: 'bar'};

setup(() => {
sandbox = sinon.sandbox.create();
sandbox.stub(chanceStub, 'bool');
sandbox.stub(chanceStub, 'date');
sandbox.stub(chanceStub, 'email');
sandbox.stub(chanceStub, 'natural');
sandbox.stub(chanceStub, 'string');
sandbox.stub(chanceStub, 'url');
sandbox.stub(chanceStub, 'word');
chanceStub = sandbox.stub(chance);
any = proxyquire('../../any', {
chance: sinon.stub().returns(chanceStub)
});
});

teardown(() => {
sandbox.restore();
});

test('that only positive integers are generated', () => {
var int = 'foo';
var int = chance.natural();
chanceStub.natural.withArgs(options).returns(int);

assert.equal(any.integer(options), int);
});

test('that a string is generated', () => {
var str = 'foo';
chanceStub.string.withArgs(options).returns(str);
var string = chance.string();
chanceStub.string.withArgs(options).returns(string);

assert.equal(any.string(options), str);
assert.equal(any.string(options), string);
});

test('that a url is generated', () => {
var url = 'foo';
var url = chance.url();
chanceStub.url.withArgs(options).returns(url);

assert.equal(any.url(options), url);
});

test('that a url is generated', () => {
var word = 'foo';
var word = chance.word();
chanceStub.word.returns(word);

assert.equal(any.word(options), word);
});

test('that a boolean is generated', () => {
var boolean = 'foo';
var boolean = chance.bool();
chanceStub.bool.returns(boolean);

assert.equal(any.boolean(options), boolean);
});

test('that an email is generated', () => {
var email = 'foo';
var email = chance.email();
chanceStub.email.returns(email);

assert.equal(any.email(options), email);
});

test('that a date string is generated', () => {
var date = 'foo';
var date = chance.date();
chanceStub.date.withArgs({string: true}).returns(date);

assert.equal(any.date(options), date);
Expand Down

0 comments on commit cd358cf

Please sign in to comment.