WebReflection / hyperHTML

A Fast & Light Virtual DOM Alternative
ISC License
3.06k stars 112 forks source link

"original.cloneNode is not a function" using hyperhtml with basichtml #400

Closed Golmote closed 4 years ago

Golmote commented 4 years ago

Hello,

I'm encountering an error that seems quite similar to the one described in #190, except I'm using basichtml.

Below is the Minimal, Reproducible Example I could come up with. Am I doing something wrong that I can't see?

import {Document} from "basichtml";
import hyper from "hyperhtml";

it('should work', () => {
    global.window = global;
    global.document = new Document();

    const root = document.createElement('div');
    const cls = 'foo';

    // This test passes
    expect(() => {
        hyper(root)`<div class="foo"></div>`;
    }).not.toThrow();

    // This test fails
    // TypeError: original.cloneNode is not a function
    // Tagger.attribute (node_modules/hyperhtml/cjs/objects/Updates.js:176:34)
    expect(() => {
        hyper(root)`<div class=${cls}></div>`;
    }).not.toThrow();
});

(I run that test using Jest. hyperhtml and basichtml are both in their latest versions, 2.32.2 and 2.3.0, respectively.)

WebReflection commented 4 years ago

the whole library is tested via basicHTML https://github.com/WebReflection/hyperHTML/blob/master/test/test.js and I've just tried this on top:

const root = document.createElement('div');
const cls = 'foo';
console.log(hyperHTML(root)`<div class="foo"></div>` === root);
console.log(hyperHTML(root)`<div class=${cls}></div>` === root);

it works without issues.

Golmote commented 4 years ago

After more digging, TIL that Jest runs the tests in a jsdom environment by default...

So if anyone runs into this issue, the fix seems to be setting Jest's testEnvironment to "node".

Thank you for your time!