How do you debug Jasmine tests with Resharper?

前端 未结 4 1112
野趣味
野趣味 2020-12-23 17:47

I can\'t find a way to debug (walk through) JavaScript code when running Jasmine tests with Resharper in Visual Studio 2012. I tried running tests with browser (Chrome) but

相关标签:
4条回答
  • 2020-12-23 18:19

    Try to use debugger keyword. Simply add the following line to the code you want to debug (perhaps into the spec):

    debugger;
    

    It invokes any available debugging functionality. It doesn't work in IE but works pretty well in Chrome (you wrote you use it so I guess it's enough just for debugging).

    Of course, after that be sure to remove the debugger keyword! Perhaps there is no really simple way how to avoid it in production code in general (in case you will use it not only in spesc) but if you are interested in this SO question could be helpful.

    0 讨论(0)
  • 2020-12-23 18:22

    I know this is an old question and this answer is slightly off topic but if you don't want to interfere with the callback Chutzpah test runner context menu could support you here. Run the tests in resharper/phantomjs (so you don't get tab explosion) and debug in Chrome (or the your preferred browser) fired off a right click:

    Chutzpah Test Runner Context Menu Extension

    0 讨论(0)
  • 2020-12-23 18:29

    Since I didn't got debugger; to work I found another solution. By adding the following to my test, resharper won't be notified that the test has finished so we can set debug breakpoints in the opened browser (I use chrome) and update (F5) the page.

    jasmine.getEnv().currentRunner_.finishCallback = function () {};
    

    Since Jasmine 2.0 you need to use:

    ReSharperReporter.prototype.jasmineDone = function () { };
    

    Stop the tests in resharper testrunner window when you're done.

    Also this can be done for QUnit

    QUnit.moduleDone = function(){}
    
    0 讨论(0)
  • 2020-12-23 18:46

    As I posted on Debugging jasmine tests with resharper and phantom js

    I got debugger; to work by setting IE 11 as my test browser in ReSharper options. The cool thing is that you can set your breakpoints in the Visual Studio version of the code and set through and debug using Visual Studio. You really do not need to interact with the browser.

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