Quill.js和zombie.js

试图在zombie.js无头浏览器中testingquill.js编辑器(contenteditable div)。

  1. 抱怨关于document.getSelection丢失
  2. 抱怨关于document.createTreeWalker丢失
  3. 如果我使用编辑器的DOM节点手动分派更改事件,似乎没有响应。

任何人都知道如何做这个工作?

好的,这是我发现的:

  1. document.getSelection不支持zombie.js使用的jsdom的当前(旧版本)。 我现在不得不猴子补丁。 有一个未决的公关zombie.js应该更新jsdom到一个更高的版本,这些是可用的: https : //github.com/assaf/zombie/issues/939
  2. document.createTreeWalker – 相同
  3. 事实上,quill.js正在监听“keyup”或“keydown”,而不是“change”,所以需要调用它们。

下面是缺less的DOM方法的一些可怕的猴子补丁,结果certificate对于testingquill.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; } );