Unit testing 无法比较karma/jasmine/PhantomJS测试中的HTML字符串,因为图标错误
我有一个测试,它(应该)检查我的工厂呈现的元素html是否正确。然而,这个元素包含材质图标,在这个测试中似乎不可能比较它的HTML 简化测试用例:Unit testing 无法比较karma/jasmine/PhantomJS测试中的HTML字符串,因为图标错误,unit-testing,phantomjs,karma-jasmine,Unit Testing,Phantomjs,Karma Jasmine,我有一个测试,它(应该)检查我的工厂呈现的元素html是否正确。然而,这个元素包含材质图标,在这个测试中似乎不可能比较它的HTML 简化测试用例: describe( 'Compile: ', function () { it( 'compare two html strings and should be equal', function () { var mockEl = $( '<i class="material-icons"></i
describe( 'Compile: ', function () {
it( 'compare two html strings and should be equal', function () {
var mockEl = $( '<i class="material-icons"></i>' )
;
expect( mockEl[0].outerHTML ).toBe(
'<i class="material-icons"></i>'
);
} );
} );
description('Compile:',函数(){
它('比较两个html字符串并应相等',函数(){
var mockEl=$(';')
;
预期(mockEl[0].outerHTML.toBe(
“;”
);
} );
} );
在结果I中,测试抛出错误:
Expected <i class="material-icons"></i>' to be '<i class="material-icons"></i>'.
应为' 为“;”。
这是Chrome控制台中图标jQuery对象文本的外观:
尝试使用unicode值进行比较,如下所示
expect( mockEl[0].outerHTML ).toBe(
'<i class="material-icons">\ue24b</i>'
);
expect(mockEl[0].outerHTML).toBe(
“\ue24b”
);