No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    console.log() not allowed in Jest tests

    CLI
    eslint jest test
    2
    4
    4776
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Jezzta667
      Jezzta667 last edited by

      I am using the @quasar/testing harness for Jest and everything is fine except that I can not use console.log() in tests, instead the console shows the following error:

      Do not use console.log() in production

      It even persists when I go to .eslintrc.js and disable the line:

      // 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',

      This leads me to conclude that there must be some other .eslintrc.js file that is connected to the Jest environment.

      Why would the Jest environment be set up to be detected as production???

      Can somebody please tell me how to correct this?

      Thank you.

      1 Reply Last reply Reply Quote 0
      • nothingismagick
        nothingismagick last edited by

        Hi,

        In your /test/jest/jest.setup.js file, there is this line:
        console.log = jest.fn(() => { throw new Error(‘Do not use console.log() in production’) })

        Feel free to comment it out.

        Jezzta667 1 Reply Last reply Reply Quote 1
        • nothingismagick
          nothingismagick last edited by

          On a side note, console.log is not your friend. It blocks javascript threads, but I’ll take your experience and turn it off by default so that users have to “opt in”.

          1 Reply Last reply Reply Quote 1
          • Jezzta667
            Jezzta667 @nothingismagick last edited by Jezzta667

            @nothingismagick thank you for your help. I suspect I must have had case-matching turned on during the search for that line of code, so apologies for the silly question.

            I would be happy to forego console.log() and begin using the Chrome debugger but I have been unable to get this to work with Quasar. I have tried the following:

            1. Add debugger statement to the test code
            2. Run the tests using yarn test:unit:debug
            3. Navigate to ‘chrome://inspect’
            4. Click on the ‘inspect’ link for Remote Target: jest file:///

            New Chrome window opens with:

            Uncaught Error: Cannot find module '<my-project-folder>\jest'
            

            A guide to accessing debugging would be a great addition to the Quasar Testing documentation. 🙂

            1 Reply Last reply Reply Quote 0
            • First post
              Last post