unexpected-sinon
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -29,3 +29,3 @@ // Copyright (c) 2013 Sune Simonsen <sune@we-knowhow.dk> | ||
} else { | ||
factory(root.expect, root.sinon); | ||
factory(root.weknowhow.expect, root.sinon); | ||
} | ||
@@ -71,3 +71,5 @@ }(this, function (expect, sinon) { | ||
var args = [this.obj].concat(Array.prototype.slice.call(arguments)); | ||
if (this.flags.always) { | ||
if (this.flags.always && this.flags.exactly) { | ||
sinon.assert.alwaysCalledWithExactly.apply(null, args); | ||
} else if (this.flags.always) { | ||
sinon.assert.alwaysCalledWith.apply(null, args); | ||
@@ -86,3 +88,11 @@ } else if (this.flags.exactly) { | ||
expect.addAssertion('[always] threw', function (value) { | ||
if (this.flags.always) { | ||
sinon.assert.alwaysThrew(this.obj, value); | ||
} else { | ||
sinon.assert.threw(this.obj, value); | ||
} | ||
}); | ||
return expect; | ||
})); |
{ | ||
"name": "unexpected-sinon", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -164,4 +164,2 @@ # Unexpected-sinon | ||
## TODO | ||
### was never called with | ||
@@ -171,2 +169,6 @@ | ||
```js | ||
expect(spy, 'was never called with', 'bar', sinon.match.truthy); | ||
``` | ||
### was called with exactly | ||
@@ -176,2 +178,8 @@ | ||
```js | ||
expect(spy, 'was called with exactly', 'foo', 'bar', sinon.match.truthy); | ||
``` | ||
## TODO | ||
### was always called with exactly | ||
@@ -178,0 +186,0 @@ |
@@ -80,2 +80,3 @@ describe('unexpected.sinon', function () { | ||
}); | ||
it('fails if spy was not called exactly three times', function () { | ||
@@ -102,2 +103,3 @@ expect(function () { | ||
}); | ||
it('fails if the spy was not called exactly number of times', function () { | ||
@@ -128,2 +130,3 @@ expect(function () { | ||
}); | ||
it('fails if the provided spies where not called in the given order', function () { | ||
@@ -196,2 +199,3 @@ expect(function () { | ||
}); | ||
it('fails if the spy was not called with the provided arguments', function () { | ||
@@ -211,2 +215,3 @@ expect(function () { | ||
}); | ||
it('fails if the spy was called once with other arguments then the provided', function () { | ||
@@ -226,2 +231,3 @@ expect(function () { | ||
}); | ||
it('fails if the spy was called with the provided arguments', function () { | ||
@@ -237,2 +243,3 @@ expect(function () { | ||
it('passes if the spy was called with the provided arguments and no others', function () { | ||
spy('foo', 'baz', 'baz'); | ||
spy('foo', 'bar', 'baz'); | ||
@@ -251,17 +258,141 @@ expect(spy, 'was called with exactly', 'foo', 'bar', sinon.match.truthy); | ||
describe('was always called with exactly', function () { | ||
it('passes if the spy was always called with the provided arguments and no others'); | ||
it('fails if the spy was ever called with anything else than the provided arguments'); | ||
it('passes if the spy was always called with the provided arguments and no others', function () { | ||
spy('foo', 'bar', 'baz'); | ||
spy('foo', 'bar', 'baz'); | ||
expect(spy, 'was always called with exactly', 'foo', 'bar', sinon.match.truthy); | ||
}); | ||
it('fails if the spy was ever called with anything else than the provided arguments', function () { | ||
expect(function () { | ||
spy('foo', 'bar', 'baz'); | ||
spy('foo', 'bar', 'baz', 'qux'); | ||
expect(spy, 'was always called with exactly', 'foo', 'bar', sinon.match.truthy); | ||
}, 'to throw exception', /expected spy to always be called with exact arguments foo, bar, truthy/); | ||
}); | ||
}); | ||
describe('threw', function () { | ||
// TODO test with type string and object | ||
it('passes if the spy threw the given exception'); | ||
it('fails if the spy never threw the given exception'); | ||
describe('without arguments', function () { | ||
it('passes if the spy threw an exception', function () { | ||
var stub = sinon.stub(); | ||
stub.throws(); | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'threw'); | ||
}); | ||
it('fails if the spy never threw an exception', function () { | ||
expect(function () { | ||
expect(spy, 'threw'); | ||
}, 'to throw exception', /spy did not throw exception/); | ||
}); | ||
}); | ||
describe('given a string as argument', function () { | ||
it('passes if the spy threw an exception of the given type', function () { | ||
var stub = sinon.stub(); | ||
stub.throws('TypeError'); | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'threw', 'TypeError'); | ||
}); | ||
it('fails if the spy never threw an exception of the given type', function () { | ||
expect(function () { | ||
var stub = sinon.stub(); | ||
stub.throws('Error'); | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'threw', 'TypeError'); | ||
}, 'to throw exception', /!Error/); | ||
}); | ||
}); | ||
describe('given a object as argument', function () { | ||
it('passes if the spy threw the given exception', function () { | ||
var stub = sinon.stub(); | ||
var error = new Error(); | ||
stub.throws(error); | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'threw', error); | ||
}); | ||
it('fails if the spy never threw the given exception', function () { | ||
expect(function () { | ||
var stub = sinon.stub(); | ||
stub.throws(new TypeError()); | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'threw', new Error()); | ||
}, 'to throw exception', /!TypeError/); | ||
}); | ||
}); | ||
}); | ||
describe('always threw', function () { | ||
// TODO test with type string and object | ||
it('passes if the spy always threw the given exception'); | ||
it('fails if the spy did not always threw the given exception'); | ||
describe('without arguments', function () { | ||
it('passes if the spy always threw an exception', function () { | ||
var stub = sinon.stub(); | ||
stub.throws(); | ||
try { stub(); } catch (e) {} | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'always threw'); | ||
}); | ||
it('fails if the spy did not always threw an exception', function () { | ||
expect(function () { | ||
var hasThrown = false; | ||
var spy = sinon.spy(function () { | ||
if (!hasThrown) { | ||
hasThrown = true; | ||
throw Error(); | ||
} | ||
}); | ||
try { spy(); } catch (e) {} | ||
spy(); | ||
expect(spy, 'always threw'); | ||
}, 'to throw exception', /spy did not always throw exception/); | ||
}); | ||
}); | ||
describe('given a string as argument', function () { | ||
it('passes if the spy always threw an exception of the given type', function () { | ||
var stub = sinon.stub(); | ||
stub.throws('Error'); | ||
try { stub(); } catch (e) {} | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'always threw', 'Error'); | ||
}); | ||
it('fails if the spy did not always threw an exception of the given type', function () { | ||
expect(function () { | ||
var stub = sinon.stub(); | ||
stub.throws('Error'); | ||
try { stub(); } catch (e) {} | ||
stub.throws('TypeError'); | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'always threw', 'Error'); | ||
}, 'to throw exception', /!TypeError/); | ||
}); | ||
}); | ||
describe('given a object as argument', function () { | ||
it('passes if the spy always threw the given exception', function () { | ||
var stub = sinon.stub(); | ||
var error = new Error(); | ||
stub.throws(error); | ||
try { stub(); } catch (e) {} | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'always threw', error); | ||
}); | ||
it('fails if the spy did not always threw the given exception', function () { | ||
expect(function () { | ||
var stub = sinon.stub(); | ||
var error = new Error(); | ||
stub.throws(error); | ||
try { stub(); } catch (e) {} | ||
stub.throws(new TypeError()); | ||
try { stub(); } catch (e) {} | ||
expect(stub, 'always threw', error); | ||
}, 'to throw exception', /!TypeError/); | ||
}); | ||
}); | ||
}); | ||
}); |
140101
4993
195