[英]What is the best way to perform an assertion for numbers that are off by ".1" in testcafe
我需要一些幫助。這是一個奇怪的問題。基本上我正在寫一些 testcafe 測試,其中: 用戶轉到訂單摘要頁面並驗證結帳頁面上的總數是否與訂單詳細信息頁面上的總數匹配。
問題:在某些情況下,訂單詳細信息總額相差一分錢(不是一個值得很快修復的錯誤。根據開發人員的說法)。例如,在結帳頁面上,您的訂單總額為 3.50 美元。 在訂單詳細信息頁面上,總額為 3.51 美元
有沒有辦法在 testcafe 斷言中打擊額外的一分錢?
這是我的斷言的樣子:
await t
.expect(totalOnCheckoutPage)
.eql(totalOnOrderDetails);
totalOnCheckoutPage 和 totalOnOrderDetails 是選擇器變量。
您可以將自定義 util 編寫為 round。 樣本
function round(x, precision) { var y = +x + (precision === undefined ? 0.5 : precision/2); return y - (y % (precision === undefined ? 1 : +precision)); } console.log(round(3.51, 0.1)) console.log(round(3.55, 0.1))
參考: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
您可以嘗試內斷言方法
await t.expect(5).within(3, 10, 'this assertion will pass');
提取兩個值的內部文本,並添加所需的舍入范圍
https://devexpress.github.io/testcafe/documentation/test-api/assertions/assertion-api.html#within
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.