【问题标题】:Check class names of nested divs || Ember/Mocha/Chai tests?检查嵌套 div 的类名 || Ember/Mocha/Chai 测试?
【发布时间】:2018-05-06 10:58:12
【问题描述】:

所以我正在使用 Mocha 和 Chai 编写集成测试。 我是测试新手。

长话短说。

我安装了几个 Chai jQuery 插件,例如 chai-domchai-jqchai-jquery

我正在通过“ember test --server”运行测试

我有一个带有 ".navigation" 类的 div。 这个 div 有三个嵌套的 div,每个都有一个唯一的类。

在我的测试中,我正在检查父 div 是否存在:

should.exist('.navigation');

我如何“期望”其他 3 个嵌套 div 具有我想要的类?

我想要类似的东西:

expect($('.navigation)).children[0].to.have.class('flex1')

expect($('.navigation)).children().to.have.class('flex1, flex2, flex3')

expect($('.navigation)).descendants.to.have.class('flex1, flex2, flex3')

类似的东西..?

我相信的 ID 也是如此?

提前谢谢你。

月。

【问题讨论】:

  • 能否请您写下您为should.exist('.navigation'); 条件测试编写的代码是什么。也许它会帮助我们写剩下的。
  • @AhmetEmreKılınç describe.only('Show navigation bar', function() { beforeEach(function() { visit('/'); fillIn('#member_login', 'user'); fillIn('#member_password', 'pass'); should.exist('.login_button'); click('.login_button'); }); it('shows navigation bar', function() { should.exist('.navigation'); expect($('.navigation').children()).to.have.length(3) **THE REST OF THE CODE SHOULD GO HERE** }); });

标签: jquery ember.js mocha.js integration-testing chai


【解决方案1】:

没关系。我发现最好的做法是:

should.exist('.navigation');

expect($('.navigation').children()).to.have.length(3)

should.exist($('.navigation').children('.flex-left'));

或者更多的断言是:expect($('.navigation').children('.flex-left')).to.have.length(1)

expect($('.navigation').children('.flex-left').children()).to.have.length(2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    相关资源
    最近更新 更多