testdouble.js icon indicating copy to clipboard operation
testdouble.js copied to clipboard

td doesn't work with curry functions.

Open chenyil opened this issue 8 years ago • 3 comments

I was trying to replace the sinon stub with td, but it didn't work with curry functions. Is it supported by td?

   //in LanguageTranslationHelpersV2
    const deserialize = curry((key, data) => ({
      //some data
    }))

    //in the test

    //sinon works with curry function
    sinon
      .stub(LanguageTranslationHelpersV2, 'deserialize', () => curry(() => ({test: true})))

    //tried to rewrite it with td, didn't work.
    //error: undefined is not an object (evaluating 'fn(a, _b)')
    td.replace(LanguageTranslationHelpersV2, 'deserialize')
    td.when(LanguageTranslationHelpersV2.deserialize(td.matchers.anything(), td.matchers.anything()))
      .thenDo(() => curry(() => ({test: true})))

chenyil avatar Jun 26 '17 21:06 chenyil

What is defining curry in this case? Sorry, I'm familiar with the concept of currying, but I don't know what curry is in your case. It'd be very helpful if you could put together a published Runkit notebook to reproduce your issue

searls avatar Jun 27 '17 21:06 searls

@searls sorry I forgot to mention, the curry I'm using is from Ramda http://ramdajs.com/docs/#curry

chenyil avatar Jun 29 '17 22:06 chenyil

That makes more sense. If you'd be able to get your example into runkit for us so we can see it in action, that'd defnitely help (apologies for not looking at it closely otherwise, I have not used ramda)

searls avatar Jun 29 '17 23:06 searls