Skip to content

JavaScript events are not firing #34

@mdesousa

Description

@mdesousa

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);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions