我有一个功能
mutationToDom: function() {
var container = document.createElement( 'mutation' );
container.setAttribute( 'string', 'test' );
return container;
}
容器是<mutation string="test"></mutation>
在单元测试中调用此函数后如何检查它?
QUnit.test( 'check function mutationToDom', function( assert ) {
var container = testBlock.mutationToDom();
assert.ok( container === ???, 'mutation is created with correct value' );
});
尝试#1
我尝试XMLSerializer()
将 XML 转换为字符串
var containerString = new XMLSerializer().serializeToString(container);
但是,containerString
是
"<mutation xmlns="http://www.w3.org/1999/xhtml" string="test"></mutation>"
代替"<mutation string="test"></mutation>"