File tree 3 files changed +48
-2
lines changed
3 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,5 @@ reporter: spec
2
2
check-leaks : true
3
3
recursive : true
4
4
file : test/setup.js
5
+ globals :
6
+ - MessageChannel # Set/unset to test nextTick()
Original file line number Diff line number Diff line change @@ -95,9 +95,20 @@ exports.nextTick = function(callback) {
95
95
args [ i - 1 ] = arguments [ i ] ;
96
96
}
97
97
98
- setTimeout ( function ( ) {
98
+ if ( typeof MessageChannel === 'undefined' ) {
99
+ return setTimeout ( triggerCallback ) ;
100
+ }
101
+
102
+ var channel = new MessageChannel ( ) ;
103
+ channel . port1 . onmessage = function ( ) {
104
+ triggerCallback ( ) ;
105
+ channel . port1 . close ( ) ;
106
+ } ;
107
+ channel . port2 . postMessage ( '' ) ;
108
+
109
+ function triggerCallback ( ) {
99
110
callback . apply ( null , args ) ;
100
- } ) ;
111
+ }
101
112
} ;
102
113
103
114
exports . clone = function ( obj ) {
Original file line number Diff line number Diff line change @@ -45,6 +45,39 @@ describe('util', function() {
45
45
} ) ;
46
46
expect ( called ) . to . be . false ;
47
47
} ) ;
48
+
49
+ describe ( 'without MessageChannel' , function ( ) {
50
+ var _MessageChannel ;
51
+
52
+ before ( function ( ) {
53
+ _MessageChannel = global . MessageChannel ;
54
+ delete global . MessageChannel ;
55
+ } ) ;
56
+
57
+ after ( function ( ) {
58
+ global . MessageChannel = _MessageChannel ;
59
+ } ) ;
60
+
61
+ it ( 'uses a different ponyfill' , function ( done ) {
62
+ expect ( process . nextTick ) . to . be . undefined ;
63
+
64
+ util . nextTick ( function ( arg1 , arg2 , arg3 ) {
65
+ expect ( arg1 ) . to . equal ( 'foo' ) ;
66
+ expect ( arg2 ) . to . equal ( 123 ) ;
67
+ expect ( arg3 ) . to . be . undefined ;
68
+ done ( ) ;
69
+ } , 'foo' , 123 ) ;
70
+ } ) ;
71
+
72
+ it ( 'calls asynchronously' , function ( done ) {
73
+ var called = false ;
74
+ util . nextTick ( function ( ) {
75
+ called = true ;
76
+ done ( ) ;
77
+ } ) ;
78
+ expect ( called ) . to . be . false ;
79
+ } ) ;
80
+ } ) ;
48
81
} ) ;
49
82
} ) ;
50
83
} ) ;
You can’t perform that action at this time.
0 commit comments