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

后端 未结 8 1415
名媛妹妹
名媛妹妹 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 05:34

    Jasmine 1.x

    You can use:

    jasmine.log("I've got a big log.");
    

    Jasmine 2+

    Use console.log directly, as per douglas-treadwell's comment below.

    0 讨论(0)
  • 2021-02-02 05:38

    1) Go to your project directory where you have your pom.xml. Run the following command in cmd. mvn jasmine:bdd

    2) You will get the localhost URL : localhost:8234 (just an example).

    3) Run this URL in the browser. Now all your test cases gets executed.

    4) Do the Inspect element of this page. In the browser console you will be able to see all the console.log() or console.error() traces.

    0 讨论(0)
  • 2021-02-02 05:39

    Try

    console.info('foo')
    

    From the test javascripts.

    0 讨论(0)
  • 2021-02-02 05:39

    I think it is not possible.

    I had to overwrite the console.log implementation in the spec loader. i.e (using jQuery):

    var console = {
        panel: $('body').append('<div>').css({position:'fixed', top:0, right:0,background:'transparent'}),
        log: function(m){
            this.panel.prepend('<div>'+m+'</div>');
        }       
    
    };
            console.log('message 1');
            console.log('message 2');
    

    ​ here your have a functional example

    0 讨论(0)
  • 2021-02-02 05:54

    If you're desperate for any output in a Terminal window so you can have data to review after the test has completed and the browser has closed, console.error() seems to do the trick.

    0 讨论(0)
  • 2021-02-02 05:54

    I'm using jasmine 2 via guard and phantom js and have found that standard console.log messages within tests are output to the jasmine spec runner's console just fine.

    I've also found that console.log messages within the javascript code elements that I am testing do get written out to stdout but not console.log messages within the tests themselves.

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