Redirect calls to console.log() to standard output in Jasmine tests

后端 未结 8 1416
名媛妹妹
名媛妹妹 2021-02-02 05:00

I\'m using Jasmine via the jasmine-maven-plugin, and I would like to see console.log() messages in the Maven build output. Is there a way to achieve this?

If console.log

相关标签:
8条回答
  • 2021-02-02 06:00

    If you are running in a node env. You could use

    process.stdout.write("this will be send to the console");
    
    0 讨论(0)
  • 2021-02-02 06:01

    Ran into the same issue using grunt/karma/jasmine (karma-jasmine 0.2.2) -

    To go along with what Dave Sag said, I've found that all my console.log messages from the code I'm testing run fine, however nothing from my describe() {} and it() {} blocks log anything.

    I did find that you can log from a beforeEach() {} block. At least it worked for me :

    beforeEach(function() {
      this.model = new blahModel();
      console.log('this.model = ', this.model);
    });
    

    Note that this only logs in the browser console and for some reason won't log in command line. Somewhat strange when the console.log statements from the tested code block do log in the command line. I've also found what seems to be a better approach for consistent logging here.

    UPDATE : I'm actually seeing the logging working for it blocks as well, I believe I had other errors that were preventing this.

    0 讨论(0)
提交回复
热议问题