Skip to content

Commit

Permalink
Update expected output.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jan 18, 2016
1 parent 7de2c3c commit c37bde0
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 336 deletions.
16 changes: 6 additions & 10 deletions documentation/assertions/array/given-call-order.md
Expand Up @@ -24,11 +24,9 @@ expect([obj.bar, obj.foo, obj.baz], 'given call order');
```output
expected [ bar, foo, baz ] given call order
[
foo(); at theFunction (theFileName:xx:yy) // spy: expected foo to be bar
bar(); at theFunction (theFileName:xx:yy) // spy: expected bar to be foo
baz(); at theFunction (theFileName:xx:yy)
]
foo(); at theFunction (theFileName:xx:yy) // spy: expected foo to be bar
bar(); at theFunction (theFileName:xx:yy) // spy: expected bar to be foo
baz(); at theFunction (theFileName:xx:yy)
```

NOTE: This assertion has slightly different semantics from Sinon.js' own
Expand All @@ -52,9 +50,7 @@ expect([spy1, spy2, spy2], 'given call order');
```output
expected [ spy1, spy2, spy2 ] given call order
[
spy1(); at theFunction (theFileName:xx:yy)
spy2(); at theFunction (theFileName:xx:yy)
spy1(); at theFunction (theFileName:xx:yy) // spy: expected spy1 to be spy2
]
spy1(); at theFunction (theFileName:xx:yy)
spy2(); at theFunction (theFileName:xx:yy)
spy1(); at theFunction (theFileName:xx:yy) // spy: expected spy1 to be spy2
```
76 changes: 34 additions & 42 deletions documentation/assertions/array/to-have-calls-satisfying.md
Expand Up @@ -53,25 +53,23 @@ expected [ increment, noop ] to have calls satisfying
}
]
[
increment(
456 // should equal 123
); at theFunction (theFileName:xx:yy)
noop( 987 ); at theFunction (theFileName:xx:yy)
increment( 123 ); at theFunction (theFileName:xx:yy)
// returned: expected 124 to equal 557
noop( 555 ); at theFunction (theFileName:xx:yy)
increment( 666 ); at theFunction (theFileName:xx:yy)
// threw: expected Error('No, I won\'t do that')
// to satisfy { message: expect.it('not to match', /^No/) }
//
// {
// message: 'No, I won\'t do that' // should not match /^No/
// //
// // No, I won't do that
// // ^^
// }
]
increment(
456 // should equal 123
); at theFunction (theFileName:xx:yy)
noop( 987 ); at theFunction (theFileName:xx:yy)
increment( 123 ); at theFunction (theFileName:xx:yy)
// returned: expected 124 to equal 557
noop( 555 ); at theFunction (theFileName:xx:yy)
increment( 666 ); at theFunction (theFileName:xx:yy)
// threw: expected Error('No, I won\'t do that')
// to satisfy { message: expect.it('not to match', /^No/) }
//
// {
// message: 'No, I won\'t do that' // should not match /^No/
// //
// // No, I won't do that
// // ^^
// }
```

Note that the individual arguments are matched with
Expand All @@ -98,14 +96,12 @@ expect([ mySpy ], 'to have calls exhaustively satisfying', [
```output
expected [ mySpy ] to have calls exhaustively satisfying [ { args: [ ... ] } ]
[
mySpy(
{
foo: 123,
bar: 456 // should be removed
}
) at theFunction (theFileName:xx:yy)
]
mySpy(
{
foo: 123,
bar: 456 // should be removed
}
); at theFunction (theFileName:xx:yy)
```

You can also specify expected calls as a function that performs them:
Expand All @@ -129,19 +125,15 @@ expect([ spy1, spy2 ], 'to have calls satisfying', function () {

```output
expected [ spy1, spy2 ] to have calls satisfying
[
spy1( 123 );
spy2( 456 );
spy1( expect.it('to be a string') );
spy2( 789 );
]
[
spy1( 123 ); at theFunction (theFileName:xx:yy)
spy2( 456 ); at theFunction (theFileName:xx:yy)
spy1(
false // should be a string
); at theFunction (theFileName:xx:yy)
spy2( 789 ); at theFunction (theFileName:xx:yy)
]
spy1( 123 );
spy2( 456 );
spy1( expect.it('to be a string') );
spy2( 789 );
spy1( 123 ); at theFunction (theFileName:xx:yy)
spy2( 456 ); at theFunction (theFileName:xx:yy)
spy1(
false // should be a string
); at theFunction (theFileName:xx:yy)
spy2( 789 ); at theFunction (theFileName:xx:yy)
```
10 changes: 4 additions & 6 deletions documentation/assertions/spy/threw.md
Expand Up @@ -49,10 +49,8 @@ expect(stub, 'always threw', /waat/);
```output
expected myStub always threw /waat/
[
myStub(); at theFunction (theFileName:xx:yy)
// expected: threw /waat/
// expected TypeError('wat') to satisfy /waat/
myStub(); at theFunction (theFileName:xx:yy)
]
myStub(); at theFunction (theFileName:xx:yy)
// expected: threw /waat/
// expected TypeError('wat') to satisfy /waat/
myStub(); at theFunction (theFileName:xx:yy)
```
42 changes: 17 additions & 25 deletions documentation/assertions/spy/to-have-calls-satisfying.md
Expand Up @@ -28,13 +28,11 @@ expect(increment, 'to have calls satisfying', [
```output
expected increment to have calls satisfying [ { args: [ 42 ] }, { args: [ 20 ] } ]
[
increment( 42 ); at theFunction (theFileName:xx:yy)
increment(
46, // should equal 20
'yadda' // should be removed
); at theFunction (theFileName:xx:yy)
]
increment( 42 ); at theFunction (theFileName:xx:yy)
increment(
46, // should equal 20
'yadda' // should be removed
); at theFunction (theFileName:xx:yy)
```

Note that the individual arguments are matched with
Expand All @@ -61,14 +59,12 @@ expect(mySpy, 'to have calls exhaustively satisfying', [
```output
expected mySpy to have calls exhaustively satisfying [ { args: [ ... ] } ]
[
mySpy(
{
foo: 123,
bar: 456 // should be removed
}
) at theFunction (theFileName:xx:yy)
]
mySpy(
{
foo: 123,
bar: 456 // should be removed
}
); at theFunction (theFileName:xx:yy)
```

You can also specify expected calls as a function that performs them:
Expand All @@ -87,14 +83,10 @@ expect(increment, 'to have calls satisfying', function () {

```output
expected increment to have calls satisfying
[
increment( 1 );
increment( expect.it('to be a number') );
]
[
increment( 1 ); at theFunction (theFileName:xx:yy)
increment( 2 ); at theFunction (theFileName:xx:yy)
increment( 3 ); at theFunction (theFileName:xx:yy) // should be removed
]
increment( 1 );
increment( expect.it('to be a number') );
increment( 1 ); at theFunction (theFileName:xx:yy)
increment( 2 ); at theFunction (theFileName:xx:yy)
increment( 3 ); at theFunction (theFileName:xx:yy) // should be removed
```
18 changes: 7 additions & 11 deletions documentation/assertions/spy/was-called-on.md
Expand Up @@ -16,11 +16,9 @@ expect(obj.spy, 'was called on', another);
```output
expected mySpy was called on {}
[
mySpy(); at theFunction (theFileName:xx:yy)
// expected: was called on {}
// expected mySpy to be called with {} as this but was called with { spy: mySpy }
]
mySpy(); at theFunction (theFileName:xx:yy)
// expected: was called on {}
// expected mySpy to be called with {} as this but was called with { spy: mySpy }
```

You can make this assertion more strict by using the `always`
Expand All @@ -41,10 +39,8 @@ expect(obj.spy, 'was always called on', obj);
```output
expected mySpy was always called on { spy: mySpy }
[
mySpy(); at theFunction (theFileName:xx:yy)
mySpy(); at theFunction (theFileName:xx:yy)
// expected: was called on { spy: mySpy }
// expected mySpy to be called with { spy: mySpy } as this but was called with {}
]
mySpy(); at theFunction (theFileName:xx:yy)
mySpy(); at theFunction (theFileName:xx:yy)
// expected: was called on { spy: mySpy }
// expected mySpy to be called with { spy: mySpy } as this but was called with {}
```
10 changes: 4 additions & 6 deletions documentation/assertions/spy/was-called-times.md
Expand Up @@ -22,12 +22,10 @@ expect(add, 'was called times', 2);
```output
expected add was called times 2
expected
[
add( 41, 42 ); at theFunction (theFileName:xx:yy)
add( 41, 43 ); at theFunction (theFileName:xx:yy)
add( 41, 44 ); at theFunction (theFileName:xx:yy)
add( 41, 45 ); at theFunction (theFileName:xx:yy)
]
add( 41, 42 ); at theFunction (theFileName:xx:yy)
add( 41, 43 ); at theFunction (theFileName:xx:yy)
add( 41, 44 ); at theFunction (theFileName:xx:yy)
add( 41, 45 ); at theFunction (theFileName:xx:yy)
to have length 2
expected 4 to be 2
```
Expand Down
60 changes: 26 additions & 34 deletions documentation/assertions/spy/was-called-with.md
Expand Up @@ -15,14 +15,12 @@ expect(mySpy, 'was called with', 'baz', { foo: 'bar' });
```output
expected mySpy was called with 'baz', { foo: 'bar' }
[
mySpy(
{ foo: 'bar' }, // should equal 'baz'
'baz', // should equal { foo: 'bar' }
'qux',
'quux'
); at theFunction (theFileName:xx:yy)
]
mySpy(
{ foo: 'bar' }, // should equal 'baz'
'baz', // should equal { foo: 'bar' }
'qux',
'quux'
); at theFunction (theFileName:xx:yy)
```

You can make this assertion more strict using the `always` flag. Then
Expand All @@ -46,15 +44,13 @@ expect(mySpy, 'was always called with', { foo: 'bar' }, 'baz', expect.it('to be
expected mySpy
was always called with { foo: 'bar' }, 'baz', expect.it('to be truthy')
[
mySpy( { foo: 'bar' }, 'baz', 'qux', 'quux' ); at theFunction (theFileName:xx:yy)
mySpy( { foo: 'bar' }, 'baz', 'qux', 'quux' ); at theFunction (theFileName:xx:yy)
mySpy(
{ foo: 'bar' },
'baz'
// missing: should be truthy
); at theFunction (theFileName:xx:yy)
]
mySpy( { foo: 'bar' }, 'baz', 'qux', 'quux' ); at theFunction (theFileName:xx:yy)
mySpy( { foo: 'bar' }, 'baz', 'qux', 'quux' ); at theFunction (theFileName:xx:yy)
mySpy(
{ foo: 'bar' },
'baz'
// missing: should be truthy
); at theFunction (theFileName:xx:yy)
```

I case you want to ensure that the spy was called with the provided
Expand All @@ -76,14 +72,12 @@ expect(mySpy, 'was called with exactly', { foo: 'bar' }, 'baz', expect.it('to be
expected mySpy
was called with exactly { foo: 'bar' }, 'baz', expect.it('to be truthy')
[
mySpy(
{ foo: 'bar' },
'baz',
'qux',
'quux' // should be removed
); at theFunction (theFileName:xx:yy)
]
mySpy(
{ foo: 'bar' },
'baz',
'qux',
'quux' // should be removed
); at theFunction (theFileName:xx:yy)
```

It is of course also possible to combine the two flags, that will then
Expand All @@ -108,13 +102,11 @@ expect(mySpy, 'was always called with exactly', { foo: 'bar' }, 'baz', expect.it
expected mySpy
was always called with exactly { foo: 'bar' }, 'baz', expect.it('to be truthy')
[
mySpy( { foo: 'bar' }, 'baz', 'qux' ); at theFunction (theFileName:xx:yy)
mySpy( { foo: 'bar' }, 'baz', 'qux' ); at theFunction (theFileName:xx:yy)
mySpy(
{ foo: 'bar' },
'baz'
// missing: should be truthy
); at theFunction (theFileName:xx:yy)
]
mySpy( { foo: 'bar' }, 'baz', 'qux' ); at theFunction (theFileName:xx:yy)
mySpy( { foo: 'bar' }, 'baz', 'qux' ); at theFunction (theFileName:xx:yy)
mySpy(
{ foo: 'bar' },
'baz'
// missing: should be truthy
); at theFunction (theFileName:xx:yy)
```
4 changes: 1 addition & 3 deletions documentation/assertions/spy/was-called.md
Expand Up @@ -33,7 +33,5 @@ expect(add, 'was not called');
```output
expected add was not called
[
add( 42, 42 ); at theFunction (theFileName:xx:yy) // should be removed
]
add( 42, 42 ); at theFunction (theFileName:xx:yy) // should be removed
```
4 changes: 2 additions & 2 deletions documentation/assertions/spyCall/to-satisfy.md
Expand Up @@ -26,12 +26,12 @@ expect(decrement.secondCall, 'to satisfy', { args: [ 20 ] });
```

```output
expected decrement( 200 ) at theFunction (theFileName:xx:yy)
expected decrement( 200 ); at theFunction (theFileName:xx:yy)
to satisfy { args: [ 20 ] }
decrement(
200 // should equal 20
) at theFunction (theFileName:xx:yy)
); at theFunction (theFileName:xx:yy)
```

All the semantics of [to satisfy](http://unexpected.js.org/assertions/any/to-satisfy/)
Expand Down
15 changes: 7 additions & 8 deletions lib/unexpected-sinon.js
Expand Up @@ -150,16 +150,15 @@
return baseType.similar(aItem, b.args[index]);
});
},
indent: false,
multipleLine: false,
leadingNewline: false,
trailingNewline: false,
inspect: function (spyCalls, depth, output, inspect) {
this.prefix(output);
output.nl()
.indentLines()
.i().block(function (output) {
output
.block(function (output) {
output.appendItems(spyCalls, '\n');
})
.nl()
.outdentLines();
this.suffix(output);
});
}
});

Expand Down

0 comments on commit c37bde0

Please sign in to comment.