Making stubs for part

182 views
Skip to first unread message

hellboy

unread,
Mar 19, 2015, 6:00:40 AM3/19/15
to sin...@googlegroups.com
I am trying to stub for ElasticSerach Node.js client

client = new elasticsearch.Client()


#.get can be stubbed easily (in beforeEach - section on top describe - level) with:

var getStub = sinon.stub(client, 'get')

getStub
   
.withArgs({
       index
: 'database',
       type
: 'table',
       id
: 'notExistingId'
   
})
   
.yields(null, {
       found
: false
   
})

But I am not sure how can I stub update properly:.

As expected this code can not work:
var updateStub = sinon.stub(client, 'update')
           
.withArgs({
                index
: 'database',
                type
: 'table',
                id
: 'NonExistingId', // Only this parameter is important
                body
: {} // I want to create stub for any body content, but stub is created only for empty
})
.yields(null, {
   found
: false
})

Or this is wrong way/test anti-pattern?
Should I create without testCase-specific stub (in it section) without withArgs ?

Maximilian Antoni

unread,
Mar 19, 2015, 10:18:11 AM3/19/15
to sin...@googlegroups.com
You can achieve what you want with a matcher:

    sinon.stub(client, 'update').withArgs(sinon.match({ id : 'NonExistingId' })).yields(...);

-Max
--
You received this message because you are subscribed to the Google Groups "Sinon.JS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinonjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages