@@ -4,6 +4,9 @@ namespace AngleSharp.Js.Tests
4
4
using AngleSharp . Dom . Events ;
5
5
using AngleSharp . Scripting ;
6
6
using NUnit . Framework ;
7
+
8
+ using System ;
9
+ using System . Linq ;
7
10
using System . Threading . Tasks ;
8
11
9
12
[ TestFixture ]
@@ -256,6 +259,35 @@ public async Task DocumentLoadEventIsFired_Issue42()
256
259
Assert . AreEqual ( "Success!" , div ? . TextContent ) ;
257
260
}
258
261
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
+
259
291
[ Test ]
260
292
public async Task SetTimeoutWithStringAsFunction ( )
261
293
{
0 commit comments