0

我一直试图在网上找到一些信息,但还没有找到任何相关的信息。我的 ERB 文件中有一个表,其中每一行都取决于实例变量的数组迭代。例子:

显示.html.erb

    <% if @line_items.present? %>
      <% @line_items.each do |line_item| %>
          <table>
            ....
          <td>SKU</td> 
          <td><%= line_item.name %></td>
          <td id="amount"><%= number_to_currency(price_amount) %></td>
          <td id="tax"><%= number_to_currency(tax_amount) %></td>
          <td id="total"><%= number_to_currency(total) %></td>
       <% end %>
   <% end %>

在这种情况下,line_item 不是我的应用程序中的模型。line_items 作为 gRPC 端点的响应。例子:

line_items_controller.rb#show

  def show
    @line_items = MyApp::GrpcEndoping.get_line_items(params: params)
  end

我想知道一种在赛普拉斯测试中模拟行项目实例变量的方法,这样我就可以测试我的前端表及其行为。

就像是:

line-items.spec.js

    it("then the line items table should be visible", function() {
      cy.visit(showPage(line_item.id))
      cy.setInstanceVariable({ line_items: {...}).as('@line_items')

      cy.reload()

      cy.get(`[data-test-id="line-items-table"]`).should("be.visible")
    })
4

0 回答 0