Resharper 7 中的 Jasmine 和 Requirejs [英] Jasmine and Requirejs in Resharper 7
问题描述
我正在尝试在 Visual Studio 2012 中使用 jasmine 和 Resharper 7 运行一些 JavaScript 代码.我在 requirejs 的帮助下遵循 AMD 模式.但是,我还没有设法在 Resharper 测试运行器中运行我的测试.
I'm trying to run some JavaScript code using jasmine and Resharper 7 within visual studio 2012. I follow the AMD pattern with the aid of requirejs. However, i haven't managed to make my test run in the Resharper test runner.
有没有人做过类似的事情?
Has anyone managed to do anything similar to that?
推荐答案
使用命名的 requireJS 模块
Use a named requireJS Module
define("my/sut", function () {
var MySut = function () {
return {
answer: 42
};
};
return MySut;
});
并使用 Jasmine 的异步支持初始化 SUT.不要忘记参考!
And initialize the SUT with the asyncronus support of Jasmine. Don't forgot the references!
/// <reference path="~/Scripts/require.js"/>
/// <reference path="../code/sut.js" />
describe("requireJS with Jasmine and Resharper", function () {
it("should be executed", function () {
// init SUT async
var sut;
runs(function () {
require(['my/sut'], function (MyModel) {
sut = new MyModel();
});
});
waitsFor(function () {
return sut;
}, "The Value should be incremented", 100);
// run the test
runs(function () {
expect(sut.answer).toBe(42);
});
});
});
我希望这适用于更多模块.就我而言,它适用于 waitsFor '0' ms.
I hope this works with more modules. In my case it worked with waitsFor '0' ms.
这篇关于Resharper 7 中的 Jasmine 和 Requirejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!