使用 Jasmine 进行单元测试,expect().toBeVisible()
Unit testing with Jasmine, expect().toBeVisible()
我需要在执行点击事件后检测 CSS 显示值。我确定这是用户错误,但我无法让 Jasmine.js 报告单击后元素可见性是否发生了变化。
这是代码笔链接:http://codepen.io/nicholasabrams/pen/dPYoJr
这是代码本身:(这显然不是使用它的实际情况,但是它是一个非常简化的版本,可以重现我当前遇到的问题)
$('#button1').on('click', function(){
$(this).append('<button id="#button2">!!!!!</button>');
});
这是测试本身:
describe("button#1 click test", function(){
beforeEach(function(){
$('#button1').click();
});
it("Should inject a new button with #button2 as the id", function(){
expect($('#button2')).toBeVisible();
});
});
首先 -
在你的笔中,你应该为 jasmine-jquery 添加外部脚本。接下来,按钮中的按钮,根据W3C Phrasing content, but there must be no interactive content descendant.
Jasmine是非法的,请尝试附加到父级:
$('#button1').on('click', function(){
$(this).parent().append('<button id="#button2">!!!!!</button>');
});
工作笔 http://codepen.io/anon/pen/zxvGja?editors=101
相关文章:
- javascript expect.to具有多个值
- Expect toNotBe()未定义,它不是函数
- 带有expect的mocha不适用于测试错误
- 如何使EXPECT条件等待promise被解析(代码封装在方法中)
- 在我的Javascript单元测试中,expect(true).toBeTruthy()失败
- nodejs + shell(expect) +child_process
- 使用 Jasmine 进行单元测试,expect().toBeVisible()
- Jasmine:在循环中使用expect
- ASP.NET MVC DropDownList会导致回发,而我不会;t expect-似乎源于JavaScript
- 没有括号的Javascript向后感知链接,例如expect(x).not.toBe()
- expect()in.then()-jasmine单元测试,AngularJS
- 通过使用expect和比较数组中的每个值来进行Karma测试
- 当promise.then中的expect失败时,Protractor / cucumber测试套件停止运行
- TypeError: expect(..).toHaveValue不是一个函数
- Codeacademy课上的Expect.js验证问题
- 试图断言JSON对象的存在在JSON数组中使用expect js与Karma套件
- expect - response在AngularJS单元测试(Jasmine)中不起作用
- 当一切正常工作时,Protractor expect方法返回错误
- 重新定义'expect'
- 为什么在Jasmine中,我们不能将expect放在外部函数中