草庐IT

run-jasmine

全部标签

javascript - 在 Jasmine 中每次测试后如何自动恢复所有 sinon.js spy ?

有什么方法可以找到sinon.js中所有活跃的spy吗?我希望能够做这样的事情:afterEach->sinon.restoreAllSpies()it"shouldnotcreateanewMyClass",->spy=sinon.spy(window,'MyClass')expect(spy).not.toHaveBeenCalled()目前,我需要费力地(而且容易出错!)这样做:it"shouldnotcreateanewMyClass",->spy=sinon.spy(window,'MyClass')expect(spy).not.toHaveBeenCalled()wind

javascript - 如何使用 Jasmine 监视静态类方法

我有一个带有静态方法的类,我想在Jasmine中对其进行测试。我知道静态方法不能在类的实例上调用。因此,除了它找不到spyOn的方法这一事实之外,我的测试没有通过,但是如何使用Jasmine测试类中的静态方法?classFoo{staticfoobar(a,b){returna*b}}Jasmine测试it('shouldtestastaticmethod',()=>{letfoo=newFoo()spyOn(foo,'foobar')foo.foobar(2,3)expect(foo.foobar).toBe(6)}) 最佳答案

javascript - jQuery ajax :error runs even if the response is OK 200

我有一个表单,它通过AJAX提交一个表单,其中:remote=>true。查看服务器日志和FireBug,我得到响应200OK,它以以下形式返回JSON:{"email":"test@test.com"}然后我有这两个处理程序:$('#new_invitation').bind("ajax:success",function(event,data,status,xhr){alert('test');});$('#new_invitation').bind("ajax:error",function(){alert('error');});即使我返回200OK,触发的也是错误处理程序。我

javascript - 使用 jasmine 测试 Backbone 关系模型

假设我有两个简单的固定文件,一个用于用户(1),一个用于消息(2)。消息的Backbone模型如下(3)。如果我加载“MessageFixture”,我还想获得有关消息模型中指定的用户的相关信息。使用jasmine测试套件在规范View(4)中激活此目标的正确方法是什么?详情请见(4)中的评论。(1)//UserFixturebeforeEach(function(){this.fixtures=_.extend(this.fixtures||{},{Users:{valid:{status:'OK',version:'1.0',response:{users:[{id:1,name:

javascript - 如何使用 Karma、Jasmine 和 Istanbul 指定测试应涵盖哪些功能/方法

我正在尝试弄清楚如何限制我的测试,以便覆盖率报告者只考虑在为该功能专门编写测试时覆盖的功能。下面的例子来自PHPUnitdoc很好地展示了我试图实现的目标:The@coversannotationcanbeusedinthetestcodetospecifywhichmethod(s)atestmethodwantstotest:/***@coversBankAccount::getBalance*/publicfunctiontestBalanceIsInitiallyZero(){$this->assertEquals(0,$this->ba->getBalance());}如果执

javascript - Jasmine 使用 PhantomJS : ReferenceError: Can't find variable: $ 丢失了 jQuery

我想用PhantomJS在控制台中测试Jasmine使用jQuery的JS代码,但是ReferenceError:找不到变量:$我可以在浏览器中通过Jasmine正常测试代码。感谢您的帮助。$phantomjsexamples/run-jasmine.jshttp://localhost:8888/ReferenceError:Can'tfindvariable:$http://localhost:8888/public/javascripts/PhotoTable.js:59ReferenceError:Can'tfindvariable:$http://localhost:8888

javascript - Jasmine 时钟是如何工作的?

我不想花几个小时阅读代码来找到相关部分,但我很好奇jasmine是如何实现它的时钟的。有趣的是它可以用同步测试代码来测试异步代码。AFAIK,对于当前支持ES5的node.js,这是不可能的(异步函数在ES7中定义)。它是否使用类似estraverse的东西解析js代码并从同步测试构建异步测试?只是我所说的一个例子:it("cantestasynccodewithsynctestingcode",function(){jasmine.clock().install();vari=0;varasyncIncrease=function(){setTimeout(function(){++

javascript - Jasmine中 "it()"代表什么?

只是好奇it()在JasmineJavascript测试框架中代表什么函数名称。它代表“独立测试”之类的东西吗? 最佳答案 它的意思是“它”,就像“它”这个词一样。正如在测试声明中读起来像一个句子。您可以通过它的作用来描述一个对象。就这么简单。例如:BowlingballisroundBowlingballhas3holes可能转化为这样的测试层次结构:BowlingBallitisroundithasthreeholes这将转化为以下测试设置:describe(BowlingBall,function(){it('isround'

javascript - zone.js 和 Jasmine 的时钟之间的冲突

我正在使用Jasmine测试套件,其中包括“Vanilla”Jasmine测试以及针对某些Angular2组件的Jasmine测试。由于Angular2的包含,zone.js被加载。这会与Jasmine的时钟发生冲突。例如,以下测试因错误而失败,错误:JasmineClock无法安装自定义全局计时器函数。时钟已经安装了吗?describe('anasynctestwithzone.jspresent',function(){beforeEach(function(){jasmine.clock().install();});afterEach(function(){jasmine.cl

javascript - 如何在 Jasmine 中伪造地理定位器的回电

我有一个调用地理定位器的函数,但我不知道如何测试该函数。我试过监视地理定位器并返回虚假数据,但没有成功,原始功能仍在使用,所以我不得不等待,我无法使用模拟数据。//thisdoesn'tworkvarnavigator_spy=spyOn(navigator.geolocation,'getCurrentPosition').andReturn({coords:{latitude:63,longitude:143}});我该怎么做? 最佳答案 当你调用地理定位代码时,它看起来像这样:navigator.geolocation.get