Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Called with diff doesn't work #1376

Closed
coderaiser opened this issue Apr 6, 2017 · 2 comments
Closed

Called with diff doesn't work #1376

coderaiser opened this issue Apr 6, 2017 · 2 comments

Comments

@coderaiser
Copy link

coderaiser commented Apr 6, 2017

As I understood from #1179 #1203 #773 called with diff should be implemed already.

  • Sinon version : 2.1.0
  • Environment : Linux cloudcmd 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux,
  • Example URL :
  • Other libraries you are using: tape

What did you expect to happen?
I expect to see called with diff:

> tape test/*.js                                                                       
TAP version 13                                                                         
# wraptile: fn: args: first                                                            
wrong arguments in functionStub                                                        
actual: [                                                                              
  "hello111"                                                                           
]                                                                                      
                                                                                       
expected: [                                                                            
  "hello"                                                                              
]                                                                                      
                                                                                       
not ok 1 should set first args                                                         
  ---                                                                                  
    operator: ok                                                                       
    expected: true                                                                     
    actual:   false                                                                    
    at: Test.test.only.t (/home/coderaiser/wraptile/test/wraptile.js:27:7)             
  ...                                                                                  
                                                                                       
1..1                                                                                   
# tests 1                                                                              
# pass  0                                                                              
# fail  1                                                                              
                                                                                       
Command failed: tape test/*.js

What actually happens
I see no diff.

> tape test/*.js                                                                       
TAP version 13                                                                         
# wraptile: fn: args: first                                                            
not ok 1 should set first args                                                         
  ---                                                                                  
    operator: ok                                                                       
    expected: true                                                                     
    actual:   false                                                                    
    at: Test.test.only.t (/home/coderaiser/wraptile/test/wraptile.js:27:7)             
  ...                                                                                  
                                                                                       
1..1                                                                                   
# tests 1                                                                              
# pass  0                                                                              
# fail  1                                                                              
                                                                                       
Command failed: tape test/*.js

How to reproduce

Describe with code how to reproduce the faulty behaviour,
or link to code on JSBin or similar

```sh npm i sinon tape wraptile ```
<summary>
'use strict';                                                                          
                                                                                       
const test = require('tape');                                                          
const sinon = require('sinon');                                                        
                                                                                       
const wraptile = require('wraptile');

test('wraptile: fn: args: first', (t) => {                                          
    const fn = sinon.stub();                                                           
    const f = wraptile(fn, 'hello111');                                                
    const f1 = f();                                                                    
                                                                                       
    f1();                                                                              
                                                                                       
    t.ok(fn.calledWith('hello'), 'should set first args');                             
    t.end();                                                                           
});
If you need to provide a dump of a stack trace or
other lengthy material, such as 80 lines of example code,
please stuff it in a `<details>` tag such as this
to make the issue more readable. Thanks.

See this for an example

@coderaiser
Copy link
Author

sinon-called-with-diff can be used as a temporary solution it produces colorful diffs when arguments mismatch.

@mroderick
Copy link
Member

As I understood from #1179 #1203 #773 called with diff should be implemed already.

It was implemented as part of sinon.assert in #1203.

In your example, you're not using sinon.assert, you're using a stub, and then call the calledWith method on that stub, which does not produce diffs.

Something like this example should work for you:

'use strict';                                                                          
                                                                                       
const test = require('tape');                                                          
const sinon = require('sinon');                                                        
                                                                                       
const wraptile = require('wraptile');

test('wraptile: fn: args: first', (t) => {                                          
    const fn = sinon.stub();                                                           
    const f = wraptile(fn, 'hello111');                                                
    const f1 = f();                                                                    
                                                                                       
    f1();                                                                              
    
    sinon.assert.calledWith(fn, 'hello');                                                                                   
    t.end();                                                                           
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants