Giter Site home page Giter Site logo

Comments (6)

JakobJingleheimer avatar JakobJingleheimer commented on June 15, 2024 1

Gentle nudge

If you're low on capacity but the feature is acceptable, I can try to implement it.

from testdouble.js.

JakobJingleheimer avatar JakobJingleheimer commented on June 15, 2024

@searls would you have an opinion on this?

from testdouble.js.

searls avatar searls commented on June 15, 2024

I don't really understand a "global mock" in this context, as I've never made a mock that survived a single test.

If for some reason you want that, I think I'd no longer call that a "test double" and instead a fake / alternate implementation for the sake of building a test harness. And if that's the case, I'd suggest dropping down to quibble to accomplish this.

of course, as soon as I think of this, quibble doesn't support this either because it just has a single process-wide reset() function. But if one could set a context for quibbles of other modules, and took that context as an optional arguemnt in reset(), then maybe something like this could be accomplished.

from testdouble.js.

JakobJingleheimer avatar JakobJingleheimer commented on June 15, 2024

A global mock would be something that is very common in an app but that has an adverse impact on testing. For example, I have an app that interacts with IndexedDB (a browser API); aside from the spec of that util, I never want that util to be real in the rest of my test suite, so I do something like:

$ node --import ./test/setup.mjs --test ./app/**/*.test.*
// test/setup

await td.replaceEsm('…/app/storage.mjs', {
  createTransaction: mock_createTransaction,
  storage: mock_storage,
});

Then in foo.test.mjs, let's say it replaces bar.mjs. At the end of foo.test.mjs, bar.mjs should be restored, but storage.mjs should not.

I think the most flexible solution would be for td.reset() to optionally accept arguments for which modules to reset to the originals.

from testdouble.js.

searls avatar searls commented on June 15, 2024

Yeah, I hear you. I personally would rather folks used quibble directly for that, because the semantics of td.js are so organized around per-test setup and teardown (including its reset() implementation) that I think it'd be better if this lived in quibble.

That said, whether it's via named contexts like I mentioned or a list of modules to not reset (because accidentally letting a test-scoped mock survive across tests because it was missed would be bad), i'd be 👍 for a well-tested quibble PR that did this

from testdouble.js.

JakobJingleheimer avatar JakobJingleheimer commented on June 15, 2024

Hmmm, I think the ergonomics of the inverse would be rather tedious (both unexpected and not particularly what users want, as well as a bit more difficult to implement).

because accidentally letting a test-scoped mock survive across tests because it was missed would be bad

Yes 🙂 That's why I think having the default (no arguments provided) is right: unless the user chooses to do something quite specific, your concern is avoided.

And this way it's not a breaking change (td.reset() current blows everything away).

I don't know this lib well enough to know the difference between putting this in quibble vs testdouble. Quibble exists as a dependency by proxy of testdouble, so it's not extra burden on users aside from being an extra thing to know (and I think most will not expect and thus won't know where to look).

from testdouble.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.