Skip to content

Add a warning when trying to replace and already replaced function #281

Open

Description

@lumaxis

We just ran into a strange issue where our tests accidentally replaced the same function twice where the second replace then replaced the testdouble function with yet another one. The td.reset() that is then run after each test only undid the second replace which left us still with with a replaced testdouble function for the next test.

I think it would be great if testdouble could help prevent/fix this situation somehow as - to us - it was very non-obvious what was going on and took some time to debug.

Activity

  1. searls commented on Aug 15, 2017

    @searls
    Member

    Oh wow, this is a really bad thing and I had never run into it before, but I completely understand your point. I definitely think we should do this.

  2. pfleidi commented on Aug 15, 2017

    @pfleidi

    @searls Thanks for your quick response! Now that we know what we're looking for, we can make sure not to do a multiple replace()s on the same function any more. But for others, it might make sense to communicate that this can cause issues. 😄

  3. izikl commented on Jun 5, 2018

    @izikl

    Instead of a warning, as the title suggests, I think it would be better to allow replacing the same method twice but still support reseting to the original method.

  4. searls commented on Jun 5, 2018

    @searls
    Member

    I am struggling to imagine why someone would want to reset the same method twice. If there's a case for that, I feel like that a more narrowly td.func-scoped reset would probably be a better fit.

    In fact, as I've thought more about this, I feel like an error (as opposed to a warning) would be more appropriate, since the behavior folks will experience will be confusing at best and undefined at worst.

  5. natesilva commented on Apr 28, 2020

    @natesilva

    We ran into this as well. It would be nice if td.replace would throw an error if the function was already stubbed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions