microsoft / Mezzurite

Your components, timed.
Other
61 stars 10 forks source link

Add empty mock implementation for console.warn #70

Closed kawwong closed 5 years ago

kawwong commented 5 years ago

When the tests run, we swallow the console warnings that we're expecting to be called so any warnings we see are more meaningful, preventing something like this:

PASS src/listeners/onComponentEnd.test.js
  ● Console

    console.warn node_modules/jest-mock/build/index.js:860
      COMPONENT_END emitted before COMPONENT_START for component id: id
    console.warn node_modules/jest-mock/build/index.js:860
      COMPONENT_END emitted for component id with end time: id

PASS src/listeners/onComponentStart.test.js
  ● Console

    console.warn node_modules/jest-mock/build/index.js:860
      COMPONENT_START emitted for existing component id: id

PASS src/reducers/components.test.js
PASS src/events/dispatchComponentsChanged.test.js
PASS src/listeners/onComponentRemove.test.js
cn894 commented 5 years ago

Wouldn't this swallow all warnings from console.warn(), even the ones that are unexpected?

kawwong commented 5 years ago

I think Jest has its own closure per describe, so it would only swallow within the describes in which the spies are active. We could change it so that the console.warn spy is only active in the relevant tests.

cn894 commented 5 years ago

If we really want to be certain, I think you're right. We'd only set up the spy per relevant test, but I don't think it's worth doing at the moment, especially given the fact that I expect us to refactor the action validation, which are pure functions, out of the listener. I think we can capture this concern as an issue and explore it in the upcoming weeks.

cn894 commented 5 years ago

I captured the open question in the new issue. I like keeping our Jest test output clean. Approving.