Skip to content

Commit

Permalink
Added unit test to check expected DocumentReadyState values
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebbs128 committed Jun 11, 2023
1 parent efb949e commit 3fb3c45
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/AngleSharp.Js.Tests/FireEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace AngleSharp.Js.Tests
using AngleSharp.Dom.Events;
using AngleSharp.Scripting;
using NUnit.Framework;

using System;
using System.Linq;
using System.Threading.Tasks;

[TestFixture]
Expand Down Expand Up @@ -256,6 +259,35 @@ public async Task DocumentLoadEventIsFired_Issue42()
Assert.AreEqual("Success!", div?.TextContent);
}

[Test]
public async Task DocumentReadyStateIsComplete_Issue86()
{
var cfg = Configuration.Default.WithJs().WithEventLoop();
var html = @"<!doctype html>
<html>
<body>
<script>
document.onreadystatechange = function() {
var element = document.createElement('div');
element.textContent = document.readyState;
document.body.appendChild(element);
};
</script>
</body>";
var context = BrowsingContext.New(cfg);
var document = await context.OpenAsync(m => m.Content(html))
.WhenStable();

var divs = document.GetElementsByTagName("div");

// expected value will vary depending on AngleSharp package version
// 1.0.2 and greater, expected value will be { "interactive", "complete"
// prior to 1.0.2, expected value will be { "1", "2" }
var expected = new[] { DocumentReadyState.Interactive, DocumentReadyState.Complete }
.Select(e => e.GetOfficialName() ?? Convert.ToInt32(e).ToString());
CollectionAssert.AreEqual(expected, divs.Select(d => d.TextContent));
}

[Test]
public async Task SetTimeoutWithStringAsFunction()
{
Expand Down

0 comments on commit 3fb3c45

Please sign in to comment.