@@ -17,6 +17,51 @@ test(t => {
17
17
assert_true ( s . aborted ) ;
18
18
19
19
c . abort ( ) ;
20
- } , "AbortController() basics" ) ;
20
+ } , "AbortController abort() should fire event synchronously" ) ;
21
+
22
+ test ( t => {
23
+ const controller = new AbortController ( ) ;
24
+ const signal = controller . signal ;
25
+ assert_equals ( controller . signal , signal ,
26
+ "value of controller.signal should not have changed" ) ;
27
+ controller . abort ( ) ;
28
+ assert_equals ( controller . signal , signal ,
29
+ "value of controller.signal should still not have changed" ) ;
30
+ } , "controller.signal should always return the same object" ) ;
31
+
32
+ test ( t => {
33
+ const controller = new AbortController ( ) ;
34
+ const signal = controller . signal ;
35
+ let eventCount = 0 ;
36
+ signal . onabort = ( ) => {
37
+ ++ eventCount ;
38
+ } ;
39
+ controller . abort ( ) ;
40
+ assert_true ( signal . aborted ) ;
41
+ assert_equals ( eventCount , 1 , "event handler should have been called once" ) ;
42
+ controller . abort ( ) ;
43
+ assert_true ( signal . aborted ) ;
44
+ assert_equals ( eventCount , 1 ,
45
+ "event handler should not have been called again" ) ;
46
+ } , "controller.abort() should do nothing the second time it is called" ) ;
47
+
48
+ test ( t => {
49
+ const controller = new AbortController ( ) ;
50
+ controller . abort ( ) ;
51
+ controller . signal . onabort =
52
+ t . unreached_func ( "event handler should not be called" ) ;
53
+ } , "event handler should not be called if added after controller.abort()" ) ;
54
+
55
+ test ( t => {
56
+ const controller = new AbortController ( ) ;
57
+ const signal = controller . signal ;
58
+ signal . onabort = t . step_func ( e => {
59
+ assert_equals ( e . type , "abort" , "event type should be abort" ) ;
60
+ assert_equals ( e . target , signal , "event target should be signal" ) ;
61
+ assert_false ( e . bubbles , "event should not bubble" ) ;
62
+ assert_true ( e . isTrusted , "event should be trusted" ) ;
63
+ } ) ;
64
+ controller . abort ( ) ;
65
+ } , "the abort event should have the right properties" ) ;
21
66
22
67
done ( ) ;
0 commit comments