尝试在zombie.js无头浏览器中测试quill.js编辑器(contenteditable div)。
任何人都知道如何使这项工作?
答案 0 :(得分:3)
好的,这是我发现的:
下面是一些遗漏的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;
} );