简体   繁体   English

JavaScript:使用jasmine进行toLocaleString()测试

[英]JavaScript: toLocaleString() testing with jasmine

I have an issue where Jasmine.js (2.4.1) is not able to test the output of toLocaleString. 我有一个问题,Jasmine.js(2.4.1)无法测试toLocaleString的输出。 Given the code on jsfiddle; 鉴于jsfiddle上的代码; https://jsfiddle.net/2utf6mb3/ https://jsfiddle.net/2utf6mb3/

var options = {
   style: "currency",
   currency: "CHF"
};

var number = 1000000;
var result = number.toLocaleString("DE-CH", options); 
//"CHF 1'000'000.00" does not work with toEqual
var result = number.toLocaleString("DE-CH"); 
//"1'000'000" works with toBe() or toEqual()

I have many numbers that needs to be formatted with or without currency. 我有许多数字需要使用或不使用货币进行格式化。 The test without currency (additional options object) works fine with a "toBe" or "toEqual" matcher. 没有货币的测试(附加选项对象)适用于“toBe”或“toEqual”匹配器。 But as soon as I have a currency option added, both matching options won't work. 但是,只要我添加了货币选项,两个匹配选项都不起作用。 At least, for me, the "toEqual" matching should work. 至少对我来说,“toEqual”匹配应该起作用。 Am I missing something here? 我在这里错过了什么吗?

Your regex test works if you replace the space following CHF to a . 如果将CHF后面的空格替换为a,则可以使用正则表达式测试。 (dot). (点)。 result.charCodeAt(3) returns 160, which is not a space. result.charCodeAt(3)返回160,这不是空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM