我在这里做一个简单的测试,但是我已经看到很多人无意中遇到了这个问题,但不幸的是,我找不到解决方案,所以,因此,我征求你的意见. 现在,我在一个链接中有这个字符串对象:
...
<div class="price">12,45 €</div>
...
我创建了这个小测试来检查字符串值:
import { t, Selector } from 'testcafe';
fixture `OfferPage`.page `https://www.verivox.de/applications/broadband/#/offer?i=eyJmaWx0ZXIiOltudWxsLDE2MDAwLDEsbnVsbCwiMDIyMSIsMSwxLDEsbnVsbCwxLDEsbnVsbCwtMSxudWxsLG51bGwsInByaWNlLWFzYyIsMixudWxsLG51bGwsbnVsbCxudWxsLG51bGwsbnVsbCxudWxsLG51bGwsNl0sImRpYWxvZyI6W251bGxdLCJvZmZlckNyaXRlcmlhIjpbIjYxMzQ0NyIsIjE4MjkyIixudWxsLCIyNCIsMywyLCI1MDAwMCIsIjEwMDAwIixudWxsLG51bGwsMSxudWxsLG51bGwsbnVsbCwiMiIsMSxudWxsLCIwMjIxIixudWxsLG51bGwsbnVsbCxudWxsLG51bGwsMSw2LG51bGwsbnVsbCxudWxsXX0%3D`;
test('1', async () => {
const string = Selector('div.price');
await t.expect(string.innerText).eql('12,45 €');
});
我在终端中得到的错误是这个:
AssertionError: expected '12,45 €' to deeply equal '12,45 €'
我真的试图找到一个解决方案,但要么我正在更改 let
中 const
的定义并尝试应用其他方法,但最终都以fail err,有不同的错误信息。
那么,在上述情况下,我该如何解决呢?
谢谢!
编辑:感谢您的提示!我编辑了这篇文章,因为我意识到我没有提到我已经尝试过你的建议......
let price = Selector('div').withAttribute('class', 'price');
const result = price.parent('div.centered-content effective-price-wrapper');
console.log(result);
await t.expect(result.innerText).eql('12,45 €');
错误:
Cannot obtain information about the node because the specified selector does not match any node in the DOM tree.
再试一次:
const string = await Selector('div.price')();
let pret = await Selector(string).innerText;
const rgx = / /gi;
await t.expect(pret.replace(rgx, '')).eql('12,45 €'.replace(rgx, ''));
错了
AssertionError: expected '12,45 €' to deeply equal '12,45 €'
我的想法已经用完了:)
最佳答案
此问题与 nonbreaking space 有关.
以下eql assertion应该在您的场景中正常工作:
await t.expect(string.innerText).eql('12,45\xa0€');
关于typescript - 断言总是返回错误(期望 'a' 深度等于 'a' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52877344/