Repository navigation
[Refactor tooltip test] Add DOM testing utility - #3791
ajduberstein wants to merge 5 commits into
Conversation
| canvasParent.appendChild(canvas); | ||
| this.canvasParent = canvasParent; | ||
| this.document.body.appendChild(canvasParent); | ||
| this.testObject = applyConstructorOrFunction(this.canvasCallback, canvas); |
There was a problem hiding this comment.
What does this do? Just call callback(canvas).
|
|
||
| export default class DocumentTest { | ||
| // Simplify the testing of deck.gl work that requires a document and canvas | ||
| constructor(canvasCallback) { |
There was a problem hiding this comment.
callback should be supplied to the method where it is used, in this case setup.
| return documentClone; | ||
| } | ||
|
|
||
| setup() { |
There was a problem hiding this comment.
This method implies that setup can be called multiple times while in reality the class only support being setup once. You should call it in the constructor in this case.
| this.testObject = applyConstructorOrFunction(this.canvasCallback, canvas); | ||
| } | ||
|
|
||
| teardown() { |
83f2601 to
f4bd47c
Compare
| const dom = new JSDOM(`<!DOCTYPE html>`); | ||
| return dom.window.document; | ||
| } | ||
| const documentClone = window.document.cloneNode(true); |
There was a problem hiding this comment.
Why do you need to clone the document? It may have heavy content during browser test.
| @@ -0,0 +1,41 @@ | |||
| /* global window */ | |||
|
|
|||
| export default class DocumentTest { | |||
There was a problem hiding this comment.
Add JSDoc for this class.
There was a problem hiding this comment.
The class name DocumentTest does not communicate what it does, e.g. the creation of a canvas. When you write tests using this class, it will be difficult for other maintainers to understand a) what the callback receives b) what the callback is supposed to return, from the code new DocumentTest(...).
| } | ||
|
|
||
| finalize() { | ||
| this.testObject.remove(); |
There was a problem hiding this comment.
This class has no control over the returned value of the user callback. Assuming testObject is a DOM element here is dangerous. There is no apparent reason why testObject has to be stored in this class. It will be a lot easier to read if you write your test like this
const testCanvas = new TestCanvas();
const myElement = setup(testCanvas.canvas);
// ...
myElement.remove();
testCanvas.finalize();There was a problem hiding this comment.
Just updated the PR, the class has been cut in favor of smaller functions and an API that looks more like the one here.
| if (typeof window === undefined || !window.document) { | ||
| const {JSDOM} = require('jsdom'); | ||
| const dom = new JSDOM(`<!DOCTYPE html>`); | ||
| documentClone = dom.window.document.cloneNode(false); |
There was a problem hiding this comment.
This node is brand new - why clone it?
| const body = window.document.createElement('body'); | ||
| html.appendChild(body); | ||
| documentClone.appendChild(html); | ||
| documentClone.body = body; |
There was a problem hiding this comment.
What is the purpose of this blob? Why don't you just use document.body?
| const dom = new JSDOM(`<!DOCTYPE html>`); | ||
| documentClone = dom.window.document.cloneNode(false); | ||
| } else { | ||
| documentClone = window.document.cloneNode(false); |
There was a problem hiding this comment.
Is there a reason you cannot attach test elements to the current document?
| } | ||
|
|
||
| /* Create a clean canvas, its parent, and a document node for testing */ | ||
| export default function setup() { |
There was a problem hiding this comment.
setupTestCanvas for clarity
dac0ad9 to
49739ee
Compare
|
Closed in favor of #3792 |
Supports increasing the test coverage on @deck.gl/jupyter-widget, where
many components of the module assume a global document and a canvas have
already been created.
See #3792 for usage
Change List