Skip to content

Testing morphdom with jsdom is tricky. #256

@ioquatix

Description

@ioquatix

Hi, thanks for creating morphdom.

It looks like testing morphdom with jsdom is quite tricky, e.g. https://runkit.com/autosponge/morphdom-jsdom-example

Having to set up a global document before invoking morphdom is tricky when there are lots of tests which might use different doms.

Might I propose adding an option, e.g. morphdom(..., ..., document: dom.window.document) or something similar that allows us to inject this into the individual calls? Alternatively, maybe we can extract it from the first argument?

I see some additional discussion here: #98

Another idea is to introduce a class which contains the state.

e.g.

morphdom = new Morphdom(document);
morphdom.morph(...)

In my own code, I have something like this:

  constructor(window) {
    this.window = window;
    this.document = window.document;

This makes testing using jsdom extremely easy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions