Giter Site home page Giter Site logo

capricorn86 / happy-dom Goto Github PK

View Code? Open in Web Editor NEW
2.9K 11.0 174.0 9.91 MB

A JavaScript implementation of a web browser without its graphical user interface

License: MIT License

JavaScript 1.00% TypeScript 99.00% Shell 0.01%
javascript typescript nodejs html dom browser whatwg react angular vue

happy-dom's People

Contributors

aralroca avatar aripalo avatar atyn avatar ayc0 avatar btea avatar capricorn86 avatar cschulz avatar danielrentz avatar daveed07 avatar davidortnercybercom avatar demivan avatar dkocsis-emarsys avatar fatihcure-jf avatar fcapolini avatar igx89 avatar jledentu avatar luca992 avatar malko avatar mas0nshi avatar mash-graz avatar maxmilton avatar mpope9 avatar nmengual avatar odanado avatar ottoszika avatar romansp avatar russiancow avatar schleuse avatar takaya1992 avatar tkrotoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

happy-dom's Issues

Using sizzle for querySelectors?

Sizzle is a selector engine used by jQuery. It was there before querySelectorAll and similar methods. Now, it uses querySelectorAll if available.

I've seen there are changes in happy-dom selectors on v1.0.0 branch, but maybe it's still valuable to use Sizzle? I gave it a quick try with happy-dom, but unfortunately, Sizzle expects window object to be available. We could experiment with it further (I think even contributing in Sizzle isn't a problem), but the question is - is this worth it? What do you think?

DOMTokenList.add bug that allows adding tokens that contains HTML space characters

I have a function that uses the classList to add/remove class names.
I mistakenly added a two classes as one string with a space to separate them, the test PASSED but in production it failed:
"Uncaught DOMException: Failed to execute 'add' on 'DOMTokenList': The token provided ('a b') contains HTML space characters, which are not valid in tokens"

//func.js
export function applyClassName({
	oldValue,
	newValue,
	element,
	defaultValue = ""
}) {
	if (newValue) {
		if (oldValue) {
			element.classList.remove(oldValue);
		}
		element.classList.add(newValue);
	} else if (oldValue) {
		element.classList.remove(oldValue);
		element.classList.add(defaultValue);
	}
}
//func.test.js
import { Window } from "happy-dom";
import { applyClassName } from "./func";

const window = new Window();
const document = window.document;

test.only("Test space within class name", () => {
	const myDiv = document.createElement("div");
	applyClassName({newValue: "a b", element: myDiv});
	expect(myDiv.className).toBe("a b");
});

I expect the test to fail because it will throw an exception, but using happy-dom it dosen't, it passes.

React issue

Running tests for enhook, getting the following.

# react
(node:5736) UnhandledPromiseRejectionWarning: TypeError: Right-hand side of 'instanceof' is not an object
    at getActiveElementDeep (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:8903:18)
    at getSelectionInformation (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:8934:21)
    at prepareForCommit (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:9447:26)
    at commitRootImpl (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:24973:5)
    at unstable_runWithPriority (C:\projects\enhook\node_modules\scheduler\cjs\scheduler.development.js:818:12)
    at runWithPriority$2 (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:12130:10)
    at commitRoot (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:24889:3)
    at finishSyncRender (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:24296:3)
    at performSyncWorkOnRoot (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:24274:9)
    at scheduleUpdateOnFiber (C:\projects\enhook\node_modules\react-dom\cjs\react-dom.development.js:23665:7)
(node:5736) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

Not sure what's the reason, due to incredibly obscure nature of react I can't even figure out where the error is coming from.
I'll just leave it here in hope somebody else will stumble upon it too, with less vague context.

slot element is null when querying it with '>'

when trying to get the slot element I receive null!

//<div class="card-footer"><slot name="footer"></slot></div>
console.info(`${this.shadowRoot.querySelector(".card-footer")}`);// => the div element
console.info(`${this.shadowRoot.querySelector(".card-footer > slot")}`);// => null
console.info(`${this.shadowRoot.querySelector(".card-footer slot")}`);// => the slot element

CustomEvent is missing detail

For some weird reason CustomEvent is the same object as Event, but looking at the code they are different. CustomEvent has detail in it and extends Event.

This was found in jest-environment-happy-dom, so it might not happen when only using happy-dom.

Custom element attributeChangedCallback is being called on any attribute change

The callback attributeChangedCallback is being called on ANY attribute change, not only on the observed ones as expected.

here is a jest test to help you reproduce

import { Window } from "happy-dom";

class MyElem extends HTMLElement {
    attributeChangedCallback(attribute, oldValue, newValue) {}
    static get observedAttributes() {
        return ['my-attr'];
    }
}

const window = new Window();
const document = window.document;
let myElem;

window.customElements.define("my-elem", MyElem);

beforeEach(() => {
  document.body.innerHTML = "<my-elem id='my-elem'></my-elem>";
  myElem = document.querySelector("#my-elem");
});
describe("Make sure component is created", () => {
  //SUCCESS
  test("’Make sure <my-elem> is defined", () => {
    expect(myElem).not.toBeNull();
  });
  //SUCCESS
  test("’Make sure changing an observed attribute will triiger change callback", () => {
    const spy = jest.spyOn(myElem, 'attributeChangedCallback');
    myElem.setAttribute("my-attr", "css-class");
    expect(spy).toHaveBeenCalled();
  });
  //FAILS
  test("’Make sure changing non observed attribute will not triiger change callback", () => {
    const spy = jest.spyOn(myElem, 'attributeChangedCallback');
    myElem.setAttribute("class", "css-class");
    expect(spy).not.toHaveBeenCalled();
  });
  //FAILS
  test("’Make sure changing non observed attribute will not triiger change callback", () => {
    const spy = jest.spyOn(myElem, 'attributeChangedCallback');
    myElem.setAttribute("style", "display: block;");
    expect(spy).not.toHaveBeenCalled();
  });
  //FAILS
  test("’Make sure changing non observed attribute will not triiger change callback", () => {
    const spy = jest.spyOn(myElem, 'attributeChangedCallback');
    myElem.setAttribute("id", "other-id");
    expect(spy).not.toHaveBeenCalled();
  });
});

Classes should implement "Native" types

The class "HTMLElement" should implement the official Typescript "HTMLElement" e.g. because of two reasons:

  1. They can be used were native types are used (e.g. declared arguments)
  2. We ensure that they implement the same propeties/methods

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.