Sinon: Remove duplication: create async methods

Created on 8 Oct 2018  路  8Comments  路  Source: sinonjs/sinon

While working on the codebase tonight, I discovered some unnecessary duplication:

https://github.com/sinonjs/sinon/blob/master/lib/sinon/default-behaviors.js#L266-L272

// create asynchronous versions of callsArg* and yields* methods
forEach(Object.keys(module.exports), function (method) {
    // need to avoid creating anotherasync versions of the newly added async methods
    if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) {
        module.exports[method + "Async"] = createAsyncVersion(method);
    }
});

and

https://github.com/sinonjs/sinon/blob/master/lib/sinon/behavior.js#L216-L222

// create asynchronous versions of callsArg* and yields* methods
forEach(Object.keys(proto), function (method) {
    // need to avoid creating anotherasync versions of the newly added async methods
    if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) {
        proto[method + "Async"] = createAsyncVersion(method);
    }
});

We should refactor the code to only have one copy of this, and re-use it.

Help wanted

All 8 comments

@mroderick I'd like to pick up this task. Any suggestions on where to put a new util function?

@LEQADA that would be great 馃憤

I think you could create a file in lib/sinon/util/core

@LEQADA did you make any progress on this? I'd like to pick this up if it's not being worked on 馃槃

@morgsmccauley sorry for a long inactivity. I already started to work on the issue but didn't have time to write tests. I plan to finish it next week if it's not urgent. If it's urgent then sure take it over.
Otherwise I'd ask to give me some more days. :slightly_smiling_face:

LIke this one to find a solution for an unmaintained dependency: https://github.com/sinonjs/nise/issues/66

Great, thanks @mroderick!

Fixed with #1942

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ljian3377 picture ljian3377  路  3Comments

optimatex picture optimatex  路  4Comments

fearphage picture fearphage  路  3Comments

stephanwlee picture stephanwlee  路  3Comments

OscarF picture OscarF  路  4Comments