[英]Testing api response gives me error because replacement character � with protractor
I am facing a problem testing with protractor. 我正面临着用量角器测试的问题。
I am comparing text in my web app with an API I make requests. 我正在将我的网络应用中的文本与我提出请求的API进行比较。 When I GET a response with Postman, text is written with HTML entities as:
ú(ú) ñ(ñ)
and I handle it with a decodeHTMLEntities()
function to decode those entities. 当我使用Postman获取响应时,文本使用HTML实体编写为:
ú(ú) ñ(ñ)
并使用decodeHTMLEntities()
函数处理它以解码这些实体。 All is fine up to that point. 到目前为止一切都很好。
The problem comes when I get a ñ
or a ¿
(not encoded). 当我得到一个
ñ
或¿
(未编码)时会出现问题。 I call the API in my test and those characters are return as
so the test fails. 我在测试中调用了API,这些字符返回为
所以测试失败了。 For example: 例如:
ApiObject = {Country: 'España'}
expect('España').toBe(ApiObject.Country)
gives: Expected 'España' to be 'Espa a'
给出:
Expected 'España' to be 'Espa a'
It is not a file format error because if I do console.log('España')
, it works fine. 这不是文件格式错误,因为如果我执行
console.log('España')
,它可以正常工作。
Why can't assert be used for this. 为什么不能断言用于此。 Which comes by default in node.js
在node.js中默认出现
Positive 正
var assert = require('assert')
ApiObject = {
Country: 'España'
}
assert.equal(ApiObject.Country, 'España')
Negative 负
var assert = require('assert')
ApiObject = {
Country: 'EspañA'
}
assert.equal(ApiObject.Country, 'España')
changed the country value at last a capital 'A' 最后改变了国家价值'A'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.