AngleSharp / AngleSharp.Js

:angel: Extends AngleSharp with a .NET-based JavaScript engine.

Home Page:https://anglesharp.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JavaScript events are not firing

mdesousa opened this issue · comments

Hi, this is a great project! But I am running into a strange issue. I was not seeing the JavaScript events being fired in my code. I decided to create a new solution with a very simple test that I took from the AngleSharp.Scripting FireEventTests.cs unit tests (see below). The test passes when I run it in the AngleSharp solution but it fails when I run it from my solution. I don't understand how this is possible... am I missing something? Thanks!

    [TestMethod]
    public async Task MainAsyncTest()
    {
        var service = new JavaScriptProvider();
        var cfg = Configuration.Default.With(service);
        var html = "<!doctype html><div id=result>0</div><script>var i = 0; document.addEventListener('hello', function () { i++; document.querySelector('#result').textContent = i.toString(); }, false);</script>";
        var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(html));
        var div = document.QuerySelector("#result");
        document.Dispatch(new CustomEvent("hello"));
        Assert.AreEqual("1", div.TextContent);
        document.Dispatch(new CustomEvent("hello"));
        Assert.AreEqual("2", div.TextContent);
    }

I think I found the problem... my solution was using the latest version of Jint (2.10.3). The test does not work with that version. When I switch to version 2.9.1, it works fine.

Thanks for the heads up. I still note it as a bug such that I am forced to release a version asap that works against the latest v2 of Jint.

@mdesousa Can you try with my pull request? #37

The tests work fine now @georgiosd , thanks