typescript - 断言总是返回 err(期望 'a' 完全等于 'a')
问题描述
我在这里做一个简单的测试,但是我看到很多人偶然发现了这个问题,但不幸的是,我无法找到解决方案,因此,我正在征求您的意见。现在,我在链接中有这个字符串对象:
...
<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 €'
我真的试图找到一个解决方案,但是要么我从const
in更改定义let
并尝试应用其他方法,都以失败错误告终,并带有不同的错误消息。那么,在上述情况下,我该如何解决?谢谢!
编辑:感谢您的提示!我编辑了这篇文章,因为我意识到我没有提到我已经尝试过你的建议......
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 €'
我在这里没有想法了:)
解决方案
This issue is related to the nonbreaking space.
The following eql assertion should work properly in your scenario:
await t.expect(string.innerText).eql('12,45\xa0€');
推荐阅读
- jsf - JSF 2.3 使用来自休息服务的@PushContext
- flutter - 如何使用 MongoDB 数据库实现 Google Sign in Flutter 应用
- xcode - 编译C编译器识别源文件“CMakeCCompilerId.c”失败。编译器:/Applications/Xcode.app/......./usr/bin/cc
- django - Djongo 和 Django
- html - 关于简单 Bootstrap 3.4.1 表中缺失列的任何想法?
- javascript - FetchError:无法验证第一个证书,但我添加了rejectUnauthorized:false
- string - Powershell,使用(空格分隔)字符串作为程序的参数
- azure-devops - 如何将多个摘要上传到 Azure DevOps Server 2020 中的发布阶段?
- reactjs - 无法使用 npm install 和依赖项安装 React
- node.js - 尝试在“handleTeamsMessagingExtensionQuery”中获取用户详细信息时,“机器人不是对话名单的一部分”