Coder Social home page Coder Social logo

jest-mock-console's People

Contributors

bpedersen avatar dependabot[bot] avatar lourd avatar noriste avatar nponeccop avatar qgolsteyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jest-mock-console's Issues

Confused with released versions and what changed in v2.0.0

Hello! Love this package. So useful. Thank you for maintaining it!

I'm confused by the 2.0.0 release that was just published to NPM 2 hours ago (which GitHub's Dependabot is alerting me to), yet this repository's package.json says the latest is 1.3.0.

image

image

Was that a mistake in the published version?

What changed that warranted a major? The latest commit ~19 hours ago just looks like bug fixes, not even new features, so why not just a 1.2.4 patch?

Just wanting to understand the versioning and the difference between the repo and NPM.

v2.0.0 breaks with Jest 28

I just upgraded the packages of my app, and now tests no longer run:

➜ npx jest test/my.unit.test.ts
 FAIL  test/my.unit.test.ts
  ● Test suite failed to run

    ReferenceError: describe is not defined

      at Object.<anonymous> (node_modules/jest-mock-console/dist/index.js:16:1)
      at Object.<anonymous> (node_modules/jest-mock-console/index.js:1:103)

This worked with the pre-2.x version of this package.

My config is as follows:

{
  "jest": {
    "collectCoverage": true,
    "preset": "ts-jest",
    "setupFiles": [
      "jest-date-mock",
      "jest-mock-console"
    ],
    "setupFilesAfterEnv": [
      "jest-mock-console/dist/setupTestFramework.js"
    ],
    "testMatch": [
      "**/test/*.test.ts",
      "**/test/test.ts"
    ],
    "testRunner": "jasmine2",
    "globals": {
      "__DEV__": true,
      "ts-jest": {
        "tsconfig": {
          "noImplicitAny": false,
          "noUnusedLocals": false
        }
      }
    }
  }
}

I am using Jest 28.1.1.

Looking at the commit log of this repo, I am unsure what actually changed. This repo seems to still be at < 2.0? (Seeing #35 it seems you haven't yet pushed the code?)

setupTestFrameworkScriptFile Deprecation Warning

Summary

Update setupTestFrameworkScriptFile to setupFilesAfterEnv

Problem

When adding the following to jest.config.js

{
  setupTestFrameworkScriptFile: 'jest-mock-console/dist/setupTestFramework.js',
}

Jest reports the following:

● Deprecation Warning:

  Option "setupTestFrameworkScriptFile" was replaced by configuration "setupFilesAfterEnv", which supports multiple paths.

  Please update your configuration.

  Configuration Documentation:
  https://jestjs.io/docs/configuration.html

Context

"devDependencies": {
    "@types/jest": "^24.0.22",
    "jest": "^24.9.0",
    "jest-mock-console": "^1.0.0",
    "ts-jest": "^24.1.0",
  }

Potential Solution

The following seems to work:

{
  setupFilesAfterEnv: [
    'jest-mock-console/dist/setupTestFramework.js',
  ],
}

See Also

Jest 27: jest is not defined

ReferenceError: jest is not defined

      118 |       };
      119 |
    > 120 |       const restoreConsole = mockConsole("error");
          |                                         ^
      121 | ...

      at mockConsole (../../node_modules/jest-mock-console/dist/index.js:26:31)

I'm using these potentially relevant dependencies:

    "jest": "^27.4.3",
    "jest-mock-console": "^1.2.3",
    "ts-jest": "^27.0.7",

Looking at dist/index.js is does appear that you're not importing jest from @jest/globals which was a breaking change in Jest 26: https://jestjs.io/blog/2020/05/05/jest-26#a-new-way-to-consume-jest---jestglobals

I'm also running with the injectGlobals: false, setting in jest.config.js, setting it to true fixes this error

Using it for logging instead of log suppressing

Hi
I was about to release almost the same package but when I realized it already exists I stopped myself. Just one consideration: I developed my package it with the opposite goal of your, I didn't need to hide the annoying logging but I'd like to have access to all the stuff logged.
Jest is infamous for logging because it updates the bash output and it's hard to analyze what the testing code is logging and what you're logging in your test files (and when a test fails it could be really useful). Using a mock you can at least do something like
expect(console.log.mock.calls).toEqual([]) and immediately it outputs the full list of console log calls/params. I know that it's a workaround but it works.

So: could I update the readme and make a pull request explaining this particular use of your library? Or you prefer that I deploy on NPM a package dedicated to logging instead of hiding logging?

Thank you
Best
Stefano

Src and dist folders seem decoupled

It appears that dist as distributed to npm and held here is an older version that doesn't accept arguments.
Meanwhile src has the new feature.

Typescript support

Found this little gem of a library today, fits nicely in my testing workflow. It would be great if it could support a Typescript development environment however. Would be happy to submit a pull request if this is something you are interested in.

How do you use this with jest.requireActual?

const mockConsole = jest.requireActual( "jest-mock-console"); 

describe('api calls', () => {

  beforeAll(() => {
    expect(jest.isMockFunction(mockConsole)).toBeFalsy();

Except that line is failing the test.

I'm using automock: true, in my jest config, which is clearly part of the issue. But I should be able to use requireActual to get around that. But it doesn't appear to work.

Also tried:

const {mockConsole} = jest.requireActual( "jest-mock-console");

But then the test fails:

TypeError: mockConsole is not a function 
 
> 11 | const restoreConsole = mockConsole();

Also tried

const mockConsole = jest.requireActual( "jest-mock-console");

But then the mock-check line expect(jest.isMockFunction(mockConsole)).toBeFalsy(); fails.

mockConsole() not returning function

Calls to mockConsole() are not returning anything:

const mockConsole = require('jest-mock-console')

beforeEach(async () => {
  const consoleRestoreFn = mockConsole()
})

In this example, consoleRestoreFn ends up as undefined.

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.