【问题标题】:How to assert direct text with other childern in a div如何在 div 中与其他子项断言直接文本
【发布时间】:2015-09-14 13:13:32
【问题描述】:

我的输出 HTML 中有以下 div:

 <div class="panel-body">
     <h5 class="panel-body-heading">Comments</h5>
     Job updated.
 </div>

我有测试代码来断言这样的 cmets 标题:

assert_select 'div.panel-body'  do
    assert_select 'h5.panel-body-heading' , /#{I18n.t('comments')}/
end

我想验证 div 是否也有文本(工作已更新),我该如何断言。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 assert minitest assertions


    【解决方案1】:

    你可以使用正则表达式:

    assert_select 'div.panel-body', /Job updated./  do
        assert_select 'h5.panel-body-heading' , /#{I18n.t('comments')}/
    end
    

    或者如果文本在某个变量中:

    assert_select 'div.panel-body', /#{str_variable}/  do
        assert_select 'h5.panel-body-heading' , /#{I18n.t('comments')}/
    end
    

    来源:Rails API guide

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 2023-04-07
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多