@@ -4,6 +4,9 @@ namespace AngleSharp.Js.Tests
44 using AngleSharp . Dom . Events ;
55 using AngleSharp . Scripting ;
66 using NUnit . Framework ;
7+
8+ using System ;
9+ using System . Linq ;
710 using System . Threading . Tasks ;
811
912 [ TestFixture ]
@@ -256,6 +259,35 @@ public async Task DocumentLoadEventIsFired_Issue42()
256259 Assert . AreEqual ( "Success!" , div ? . TextContent ) ;
257260 }
258261
262+ [ Test ]
263+ public async Task DocumentReadyStateIsComplete_Issue86 ( )
264+ {
265+ var cfg = Configuration . Default . WithJs ( ) . WithEventLoop ( ) ;
266+ var html = @"<!doctype html>
267+ <html>
268+ <body>
269+ <script>
270+ document.onreadystatechange = function() {
271+ var element = document.createElement('div');
272+ element.textContent = document.readyState;
273+ document.body.appendChild(element);
274+ };
275+ </script>
276+ </body>" ;
277+ var context = BrowsingContext . New ( cfg ) ;
278+ var document = await context . OpenAsync ( m => m . Content ( html ) )
279+ . WhenStable ( ) ;
280+
281+ var divs = document . GetElementsByTagName ( "div" ) ;
282+
283+ // expected value will vary depending on AngleSharp package version
284+ // 1.0.2 and greater, expected value will be { "interactive", "complete"
285+ // prior to 1.0.2, expected value will be { "1", "2" }
286+ var expected = new [ ] { DocumentReadyState . Interactive , DocumentReadyState . Complete }
287+ . Select ( e => e . GetOfficialName ( ) ?? Convert . ToInt32 ( e ) . ToString ( ) ) ;
288+ CollectionAssert . AreEqual ( expected , divs . Select ( d => d . TextContent ) ) ;
289+ }
290+
259291 [ Test ]
260292 public async Task SetTimeoutWithStringAsFunction ( )
261293 {
0 commit comments