Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Analysis of weird test failure #2

@pedrottimark

Description

@pedrottimark

@SimenB /cc @thymikee The regression is caused by 2 bugs in jsdom package:

  1. In Check for existence of Element when comparing DOM-nody-things (#7786) (clean cherry pick version) jestjs/jest#7995 we changed isDomNode function in jasmineUtils.ts file:

    • from duck type test: obj !== null && typeof obj === 'object' && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string'
    • to instanceof test: typeof Node !== 'undefined' && obj instanceof Node
    const fragCreate = document.createDocumentFragment();
    const fragSimple = JSDOM.fragment();
    
    fragCreate instanceof Node // true
    fragSimple instanceof Node // false
    
    fragCreate instanceof DocumentFragment // true
    fragSimple instanceof DocumentFragment // false
    
    Object.prototype.toString.call(fragCreate) // '[object DocumentFragment]'
    Object.prototype.toString.call(fragSimple) // '[object DocumentFragment]'
    
    typeof fragCreate.isEqualNode // 'function'
    typeof fragSimple.isEqualNode // 'function'
  2. Serializing a fragment causes side effect enumerable symbol Symbol(SameObject caches)

    • When you commented out toMatchDiffSnapshot then both fragment instances have no enumerable properties, so test passes as false negative, even if I comment out span2.innerHTML = 'hello' to compare <span>hello</span> to <span>huh</span>

    • With toMatchDiffSnapshot then first has been serialized, so has bogus implementation symbol key, but because of reassignment to second the new instance has no keys

    • To confirm, if I call pretty-format with DOMElement plugin to serialize the second instance, then toEqual passes as false negative, because both have value of SameObject caches

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