AngleSharp / AngleSharp.Js

:angel: Extends AngleSharp with a .NET-based JavaScript engine.
https://anglesharp.github.io
MIT License
105 stars 23 forks source link

JavaScript events are not firing #34

Closed mdesousa closed 7 years ago

mdesousa commented 7 years ago

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);
    }
mdesousa commented 7 years ago

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.

FlorianRappl commented 7 years ago

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.

georgiosd commented 7 years ago

@mdesousa Can you try with my pull request? https://github.com/AngleSharp/AngleSharp.Scripting/pull/37

mdesousa commented 7 years ago

The tests work fine now @georgiosd , thanks