-
Notifications
You must be signed in to change notification settings - Fork 142
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
Call a Callback Multiple Times #397
Comments
You could specify that any number of stubbings only fire 1 time. Once satisfied they'll be effectively disabled. Because the last-stubbing-in is the first to be satisfied by an invocation, you'll need to stub them in reverse order as shown below // Subsequent calls
td.when(progress(td.callback)).thenCallback({loaded:0.8,total:3})
// Second call
td.when(progress(td.callback), {times: 1}).thenCallback({loaded:0.6,total:2})
// First call
td.when(progress(td.callback), {times: 1}).thenCallback({loaded:0.5,total:1}) Alternatively you can look at using thenDo for more freedom in creating custom or conditional behavior |
I may not have explained myself well enough. I want the myCallback to be called multiple time to simulate. The issue is that I am not testing one function at a time i am testing 2. var td = require('testdouble')
// Your steps here.
const progress = td.func();
const myCallback = td.func();
td.when(progress(td.callback)).thenCallback({loaded:0.5,total:1})
progress(myCallback)
// should essentially do
progress() 1 call
myCallback() 1 call
myCallback() 2 call
myCallback() 3 call
//essentially if i have an options like, not saying i
//need it just trying to figure out the work around to get it.
const progress = td.func();
const myCallback = td.func();
td.when(progress(td.callback))
.thenCallback({loaded:0.2,total:1})
.thenCallback({loaded:0.5,total:1})
.thenCallback({loaded:0.7,total:1})
.thenCallback({loaded:1,total:1})
//internally looks like
progress((callback)=>{
callback({loaded:0.2,total:1})
callback({loaded:0.5,total:1})
callback({loaded:0.8,total:1})
})
|
For this kind of nesting dolls scenario, I think you're going to have to write a custom function in const progress = td.func()
td.when(progress(td.matchers.isA(Function))).thenDo(cb => {
cb({loaded:0.2,total:1})
cb({loaded:0.5,total:1})
cb({loaded:0.7,total:1})
cb({loaded:1,total:1})
})
progress(console.log) /*
{ loaded: 0.2, total: 1 }
{ loaded: 0.5, total: 1 }
{ loaded: 0.7, total: 1 }
{ loaded: 1, total: 1 }
*/ |
Description
I want to simulate a callback that is fired more than once.
This of a upload function.
I have a
Issue
The issue is that i can't fire a callback more than once different arguments. Or atleast i don't know how to.
Environment
node -v
output:v10.11.0
npm -v
(oryarn --version
) output:1.12.3
npm ls testdouble
(oryarn list testdouble
) version:yarn list v1.12.3
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ testdouble@3.9.1
Done in 1.56s.
Failing Test
Example Repo
npm it
and observe the issueRunkit Notebook
var td = require('testdouble')
at the topCode-fenced Examples
The text was updated successfully, but these errors were encountered: