尝试在quill.js无头浏览器中测试zombie.js编辑器(内容可编辑div)。
有人知道怎么做吗?
发布于 2016-02-02 23:28:24
好吧,下面是我的发现:
下面是一些缺少DOM方法的可怕的猴子补丁,这些方法被证明足以测试最低限度的quill.js:
var zombie = require( "zombie" );
zombie.Pipeline.addHandler(function(browser, request, response) {
browser.document.getSelection = browser.window.getSelection = function() {
console.warn( "getSelection called - monkey-patched, incorrect implementation" );
return null;
};
browser.document.createTreeWalker = function( x ) {
console.warn( "createTreeWalker called - monkey-patched, incorrect implementation" );
return {
currentNode: x,
nextNode: function() {
if( this.currentNode.childNodes && this.currentNode.childNodes.length ) {
this.currentNode = this.currentNode.childNodes[ 0 ];
} else if( this.currentNode.nextSibling ) {
this.currentNode = this.currentNode.nextSibling;
} else if( this.currentNode.parentNode ) {
this.currentNode = this.currentNode.parentNode.nextSibling;
}
return this.currentNode || null;
}
};
};
return response;
} );https://stackoverflow.com/questions/35132394
复制相似问题