javascript 你如何使用 Resharper 调试 Jasmine 测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16222098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you debug Jasmine tests with Resharper?
提问by orad
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 the test runner closes the port as soon as the test is run and so I cannot put a breakpoint in the code. Also tried running in Internet Explorer and put breakpoints in Visual Studio but it won't attach to the process. My test has a lot of ///reference scripts that Resharper includes automatically in the test runner but I don't want to manually do this for every test that I want to debug. Please help me understand this. If you have a jasmine test that is failing, then how do you debug it?
在 Visual Studio 2012 中使用 Resharper 运行 Jasmine 测试时,我找不到调试(遍历)JavaScript 代码的方法。我尝试使用浏览器 (Chrome) 运行测试,但测试运行器在测试运行后立即关闭端口,并且所以我不能在代码中放置断点。还尝试在 Internet Explorer 中运行并在 Visual Studio 中放置断点,但它不会附加到进程中。我的测试有很多 ///reference 脚本,Resharper 将这些脚本自动包含在测试运行器中,但我不想为我想要调试的每个测试手动执行此操作。请帮助我理解这一点。如果您有一个失败的 jasmine 测试,那么您如何调试它?
采纳答案by zbynour
Try to use debugger
keyword. Simply add the following line to the code you want to debug (perhaps into the spec):
尝试使用debugger
关键字。只需将以下行添加到您要调试的代码中(可能添加到规范中):
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).
它调用任何可用的调试功能。它在 IE 中不起作用,但在 Chrome 中工作得很好(你写你使用它,所以我想它只用于调试就足够了)。
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 questioncould be helpful.
当然,之后一定要去掉debugger
关键字!也许没有真正简单的方法可以在一般的生产代码中避免它(以防您不仅在 spesc 中使用它),但如果您对这个 SO问题感兴趣可能会有所帮助。
回答by Torbj?rn Nomell
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.
由于我没有debugger;
工作,我找到了另一个解决方案。通过将以下内容添加到我的测试中,resharper 不会收到测试已完成的通知,因此我们可以在打开的浏览器(我使用 chrome)中设置调试断点并更新(F5)页面。
jasmine.getEnv().currentRunner_.finishCallback = function () {};
Since Jasmine 2.0 you need to use:
从 Jasmine 2.0 开始,您需要使用:
ReSharperReporter.prototype.jasmineDone = function () { };
Stop the tests in resharper testrunner window when you're done.
完成后在 resharper testrunner 窗口中停止测试。
Also this can be done for QUnit
这也可以为 QUnit 完成
QUnit.moduleDone = function(){}
回答by Jason Bowers
As I posted on Debugging jasmine tests with resharper and phantom js
正如我在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.
我有调试器;通过在 ReSharper 选项中将 IE 11 设置为我的测试浏览器来工作。很酷的一点是,您可以在代码的 Visual Studio 版本中设置断点,并使用 Visual Studio 进行设置和调试。您真的不需要与浏览器进行交互。
回答by jolySoft
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 测试运行器上下文菜单可以在这里支持你。在 resharper/phantomjs 中运行测试(这样您就不会出现标签爆炸)并在 Chrome(或您首选的浏览器)中进行调试,然后单击右键: