by assertion tests

This commit is contained in:
lucasfcosta 2016-02-22 17:15:34 -03:00
parent 8e8a728921
commit 10a0bbcc6a
3 changed files with 66 additions and 10 deletions

View file

@ -875,23 +875,31 @@ describe('assert', function () {
var obj = { value: 10, str: 'foo' },
heroes = ['spiderman', 'superman'],
fn = function() { obj.value += 5 },
fnDec = function() { obj.value -= 20 },
bangFn = function() { obj.str += '!' },
smFn = function() { 'foo' + 'bar' },
batFn = function() { heroes.push('batman') },
lenFn = function() { return heroes.length };
assert.changes(fn, obj, 'value');
assert.changesBy(fn, obj, 'value', 5);
assert.changesBy(fn, obj, 'value', -5);
assert.changesBy(fnDec, obj, 'value', 20);
assert.doesNotChange(smFn, obj, 'value');
assert.changesButNotBy(fnDec, obj, 'value', 1);
assert.changes(bangFn, obj, 'str');
assert.changes(batFn, lenFn);
assert.doesNotChange(smFn, lenFn);
assert.changesBy(batFn, lenFn, 1);
assert.changesButNotBy(batFn, lenFn, 2);
});
it('increase, decrease', function() {
var obj = { value: 10 },
arr = ['one', 'two'],
pFn = function() { arr.push('three') },
popFn = function() { arr.pop() },
popFn = function() { arr.pop() },
lenFn = function() { return arr.length },
incFn = function() { obj.value += 2 },
decFn = function() { obj.value -= 3 },
@ -899,15 +907,23 @@ describe('assert', function () {
assert.decreases(decFn, obj, 'value');
assert.doesNotDecrease(smFn, obj, 'value');
assert.decreasesBy(decFn, obj, 'value', 3);
assert.decreasesButNotBy(decFn, obj, 'value', 10);
assert.increases(incFn, obj, 'value');
assert.doesNotIncrease(smFn, obj, 'value');
assert.increasesBy(incFn, obj, 'value', 2);
assert.increasesButNotBy(incFn, obj, 'value', 1);
assert.decreases(popFn, lenFn);
assert.doesNotDecrease(pFn, lenFn);
assert.decreasesBy(popFn, lenFn, 1);
assert.decreasesButNotBy(popFn, lenFn, 2);
assert.increases(pFn, lenFn);
assert.doesNotIncrease(popFn, lenFn);
assert.increasesBy(pFn, lenFn, 1);
assert.increasesButNotBy(pFn, lenFn, 2);
});
it('isExtensible / extensible', function() {

View file

@ -1123,17 +1123,26 @@ describe('expect', function () {
var obj = { value: 10, str: 'foo' },
heroes = ['spiderman', 'superman'],
fn = function() { obj.value += 5 },
decFn = function() { obj.value -= 20 },
sameFn = function() { 'foo' + 'bar' },
bangFn = function() { obj.str += '!' },
batFn = function() { heroes.push('batman') },
lenFn = function() { return heroes.length };
expect(fn).to.change(obj, 'value');
expect(fn).to.change(obj, 'value').by(5);
expect(fn).to.change(obj, 'value').by(-5);
expect(decFn).to.change(obj, 'value').by(20);
expect(decFn).to.change(obj, 'value').but.not.by(21);
expect(sameFn).to.not.change(obj, 'value');
expect(sameFn).to.not.change(obj, 'str');
expect(bangFn).to.change(obj, 'str');
expect(batFn).to.change(lenFn);
expect(sameFn).to.not.change(lenFn);
expect(batFn).to.change(lenFn).by(1);
expect(batFn).to.change(lenFn).but.not.by(2);
});
it('increase, decrease', function() {
@ -1150,16 +1159,24 @@ describe('expect', function () {
expect(smFn).to.not.increase(obj, 'value');
expect(decFn).to.not.increase(obj, 'value');
expect(incFn).to.increase(obj, 'value');
expect(incFn).to.increase(obj, 'value').by(2);
expect(incFn).to.increase(obj, 'value').but.not.by(1);
expect(smFn).to.not.decrease(obj, 'value');
expect(incFn).to.not.decrease(obj, 'value');
expect(decFn).to.decrease(obj, 'value');
expect(decFn).to.decrease(obj, 'value').by(3);
expect(decFn).to.decrease(obj, 'value').but.not.by(2);
expect(popFn).to.not.increase(lenFn);
expect(nFn).to.not.increase(lenFn);
expect(pFn).to.increase(lenFn);
expect(pFn).to.increase(lenFn).by(1);
expect(pFn).to.increase(lenFn).but.not.by(2);
expect(popFn).to.decrease(lenFn);
expect(popFn).to.decrease(lenFn).by(1);
expect(popFn).to.decrease(lenFn).but.not.by(2);
expect(nFn).to.not.decrease(lenFn);
expect(pFn).to.not.decrease(lenFn);
});

View file

@ -967,17 +967,29 @@ describe('should', function() {
heroes = ['spiderman', 'superman'],
fn = function() { obj.value += 5 },
sameFn = function() { obj.value += 0 },
decFn = function() { obj.value -= 3 },
decFn = function() { obj.value -= 20 },
bangFn = function() { obj.str += '!' },
batFn = function() { heroes.push('batman') },
lenFn = function() { return heroes.length },
noFn = function() { return null };
fn.should.change(obj, 'value');
fn.should.change(obj, 'value').by(5);
fn.should.change(obj, 'value').by(-5);
fn.should.change(obj, 'value').but.not.by(10);
decFn.should.change(obj, 'value');
decFn.should.change(obj, 'value').by(20);
decFn.should.change(obj, 'value').but.not.by(19);
sameFn.should.not.change(obj, 'value');
sameFn.should.not.change(obj, 'str');
bangFn.should.change(obj, 'str');
batFn.should.change(lenFn);
batFn.should.change(lenFn).by(1);
batFn.should.change(lenFn).but.not.by(2);
noFn.should.not.change(lenFn);
});
@ -995,18 +1007,29 @@ describe('should', function() {
smFn.should.not.increase(obj, 'value');
decFn.should.not.increase(obj, 'value');
incFn.should.increase(obj, 'value');
incFn.should.increase(obj, 'value').by(2);
incFn.should.increase(obj, 'value').but.not.by(1);
smFn.should.not.decrease(obj, 'value');
incFn.should.not.decrease(obj, 'value');
decFn.should.decrease(obj, 'value');
decFn.should.decrease(obj, 'value').by(3);
decFn.should.decrease(obj, 'value').but.not.by(2);
nFn.should.not.increase(lenFn);
popFn.should.not.increase(lenFn);
pFn.should.increase(lenFn);
nFn.should.not.decrease(lenFn);
pFn.should.not.decrease(lenFn);
popFn.should.decrease(lenFn);
popFn.should.not.increase(lenFn);
pFn.should.increase(lenFn);
pFn.should.not.decrease(lenFn);
pFn.should.increase(lenFn).by(1);
pFn.should.increase(lenFn).but.not.by(2);
popFn.should.decrease(lenFn).by(1);
popFn.should.decrease(lenFn).but.not.by(2);
});
it('extensible', function() {