Skip to content

Commit 800307b

Browse files
committed
Datepicker tests: Update to QUnit 2.x, shift to use no globals
1 parent c0f1bd6 commit 800307b

File tree

4 files changed

+127
-117
lines changed

4 files changed

+127
-117
lines changed

tests/unit/datepicker/core.js

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"ui/widgets/datepicker"
4-
], function( $ ) {
5+
], function( QUnit, $ ) {
56

6-
module( "datepicker: core", {
7-
setup: function() {
7+
QUnit.module( "datepicker: core", {
8+
beforeEach: function() {
89
this.element = $( "#datepicker" ).datepicker( { show: false, hide: false } );
910
this.widget = this.element.datepicker( "widget" );
1011
},
11-
teardown: function() {
12+
afterEach: function() {
1213
this.element.datepicker( "destroy" ).val( "" );
1314
}
1415
} );
1516

16-
test( "input's value determines starting date", function( assert ) {
17+
QUnit.test( "input's value determines starting date", function( assert ) {
1718
assert.expect( 3 );
1819

1920
this.element = $( "<input>" ).appendTo( "#qunit-fixture" );
@@ -22,59 +23,62 @@ test( "input's value determines starting date", function( assert ) {
2223

2324
this.element.datepicker( "open" );
2425

25-
equal( this.widget.find( ".ui-calendar-month" ).html(), "January", "correct month displayed" );
26-
equal( this.widget.find( ".ui-calendar-year" ).html(), "2014", "correct year displayed" );
27-
equal( this.widget.find( ".ui-state-active" ).html(), "1", "correct day highlighted" );
26+
assert.equal( this.widget.find( ".ui-calendar-month" ).html(), "January", "correct month displayed" );
27+
assert.equal( this.widget.find( ".ui-calendar-year" ).html(), "2014", "correct year displayed" );
28+
assert.equal( this.widget.find( ".ui-state-active" ).html(), "1", "correct day highlighted" );
2829
} );
2930

30-
asyncTest( "base structure", function( assert ) {
31+
QUnit.test( "base structure", function( assert ) {
32+
var ready = assert.async();
3133
assert.expect( 5 );
3234

3335
var that = this;
3436

3537
this.element.focus();
3638

3739
setTimeout( function() {
38-
ok( that.widget.is( ":visible" ), "Datepicker visible" );
39-
equal( that.widget.children().length, 3, "Child count" );
40-
ok( that.widget.is( ".ui-calendar" ), "Class ui-calendar" );
41-
ok( that.widget.is( ".ui-datepicker" ), "Class ui-datepicker" );
42-
ok( that.widget.is( ".ui-front" ), "Class ui-front" );
40+
assert.ok( that.widget.is( ":visible" ), "Datepicker visible" );
41+
assert.equal( that.widget.children().length, 3, "Child count" );
42+
assert.ok( that.widget.is( ".ui-calendar" ), "Class ui-calendar" );
43+
assert.ok( that.widget.is( ".ui-datepicker" ), "Class ui-datepicker" );
44+
assert.ok( that.widget.is( ".ui-front" ), "Class ui-front" );
4345

4446
that.element.datepicker( "close" );
45-
start();
47+
ready();
4648
}, 50 );
4749
} );
4850

49-
asyncTest( "Keyboard handling: focus", function( assert ) {
51+
QUnit.test( "Keyboard handling: focus", function( assert ) {
52+
var ready = assert.async();
5053
assert.expect( 2 );
5154

5255
var that = this;
5356

54-
ok( !this.widget.is( ":visible" ), "datepicker closed" );
57+
assert.ok( !this.widget.is( ":visible" ), "datepicker closed" );
5558

5659
this.element.focus();
5760
setTimeout( function() {
58-
ok( that.widget.is( ":visible" ), "Datepicker opens when receiving focus" );
59-
start();
61+
assert.ok( that.widget.is( ":visible" ), "Datepicker opens when receiving focus" );
62+
ready();
6063
}, 100 );
6164
} );
6265

63-
asyncTest( "Keyboard handling: keystroke up", function( assert ) {
66+
QUnit.test( "Keyboard handling: keystroke up", function( assert ) {
67+
var ready = assert.async();
6468
assert.expect( 2 );
6569

6670
var that = this;
6771

68-
ok( !this.widget.is( ":visible" ), "datepicker closed" );
72+
assert.ok( !this.widget.is( ":visible" ), "datepicker closed" );
6973

7074
this.element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } );
7175
setTimeout( function() {
72-
ok( that.widget.is( ":visible" ), "Keystroke up opens datepicker" );
73-
start();
76+
assert.ok( that.widget.is( ":visible" ), "Keystroke up opens datepicker" );
77+
ready();
7478
}, 100 );
7579
} );
7680

77-
test( "Keyboard handling: input", function( assert ) {
81+
QUnit.test( "Keyboard handling: input", function( assert ) {
7882
assert.expect( 6 );
7983

8084
var that = this,
@@ -92,10 +96,10 @@ test( "Keyboard handling: input", function( assert ) {
9296
that.element
9397
.val( "" )
9498
.datepicker( "open" );
95-
ok( instance.isOpen, "datepicker is open before escape" );
99+
assert.ok( instance.isOpen, "datepicker is open before escape" );
96100

97101
that.element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
98-
ok( !instance.isOpen, "escape closes the datepicker" );
102+
assert.ok( !instance.isOpen, "escape closes the datepicker" );
99103

100104
that.element
101105
.val( "1/1/14" )
@@ -120,11 +124,12 @@ test( "Keyboard handling: input", function( assert ) {
120124
} );
121125

122126
// TODO: implement
123-
test( "ARIA", function() {
124-
expect( 0 );
127+
QUnit.test( "ARIA", function( assert ) {
128+
assert.expect( 0 );
125129
} );
126130

127-
asyncTest( "mouse", function( assert ) {
131+
QUnit.test( "mouse", function( assert ) {
132+
var ready = assert.async();
128133
assert.expect( 4 );
129134

130135
var that = this;
@@ -142,7 +147,7 @@ asyncTest( "mouse", function( assert ) {
142147

143148
that.element.val( "" ).datepicker( "refresh" );
144149
that.element.simulate( "click" );
145-
strictEqual( that.element.datepicker( "valueAsDate" ), null, "Mouse click - close" );
150+
assert.strictEqual( that.element.datepicker( "valueAsDate" ), null, "Mouse click - close" );
146151

147152
that.element.val( "4/4/08" ).datepicker( "refresh" ).datepicker( "open" );
148153
that.element.simulate( "click" );
@@ -161,7 +166,7 @@ asyncTest( "mouse", function( assert ) {
161166
"Mouse click - abandoned"
162167
);
163168

164-
start();
169+
ready();
165170
}, 100 );
166171
} );
167172

tests/unit/datepicker/events.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"ui/widgets/datepicker"
4-
], function( $ ) {
5+
], function( QUnit, $ ) {
56

6-
module( "datepicker: events", {
7-
setup: function() {
7+
QUnit.module( "datepicker: events", {
8+
beforeEach: function() {
89
this.element = $( "#datepicker" ).datepicker( { show: false, hide: false } );
910
this.widget = this.element.datepicker( "widget" );
1011
},
11-
teardown: function() {
12+
afterEach: function() {
1213
this.element.datepicker( "destroy" ).val( "" );
1314
}
1415
} );
1516

16-
test( "beforeOpen", function( assert ) {
17+
QUnit.test( "beforeOpen", function( assert ) {
1718
assert.expect( 3 );
1819

1920
var that = this;
2021

2122
this.element.datepicker( {
2223
beforeOpen: function() {
23-
ok( true, "beforeOpen event fired before open" );
24-
ok( that.element.datepicker( "widget" ).is( ":hidden" ), "calendar hidden on beforeOpen" );
24+
assert.ok( true, "beforeOpen event fired before open" );
25+
assert.ok( that.element.datepicker( "widget" ).is( ":hidden" ), "calendar hidden on beforeOpen" );
2526
},
2627
open: function() {
27-
ok( that.element.datepicker( "widget" ).is( ":visible" ), "calendar open on open" );
28+
assert.ok( that.element.datepicker( "widget" ).is( ":visible" ), "calendar open on open" );
2829
}
2930
} );
3031

@@ -36,21 +37,21 @@ test( "beforeOpen", function( assert ) {
3637
return false;
3738
},
3839
open: function() {
39-
ok( false, "calendar should not open when openBefore is canceled" );
40+
assert.ok( false, "calendar should not open when openBefore is canceled" );
4041
}
4142
} )
4243
.datepicker( "open" );
4344
} );
4445

45-
test( "change", function( assert ) {
46+
QUnit.test( "change", function( assert ) {
4647
assert.expect( 4 );
4748

4849
var shouldFire;
4950

5051
this.element.datepicker( {
5152
change: function( event ) {
52-
ok( shouldFire, "change event fired" );
53-
equal(
53+
assert.ok( shouldFire, "change event fired" );
54+
assert.equal(
5455
event.type,
5556
"datepickerchange",
5657
"change event"
@@ -71,14 +72,14 @@ test( "change", function( assert ) {
7172
this.widget.find( "tbody button" ).eq( 2 ).simulate( "mousedown" );
7273
} );
7374

74-
test( "close", function( assert ) {
75+
QUnit.test( "close", function( assert ) {
7576
assert.expect( 4 );
7677

7778
var shouldFire;
7879

7980
this.element.datepicker( {
8081
close: function() {
81-
ok( shouldFire, "close event fired" );
82+
assert.ok( shouldFire, "close event fired" );
8283
}
8384
} );
8485

@@ -103,31 +104,32 @@ test( "close", function( assert ) {
103104
this.widget.find( "tbody tr:first button:first" ).simulate( "mousedown" );
104105
} );
105106

106-
test( "open", function( assert ) {
107+
QUnit.test( "open", function( assert ) {
107108
assert.expect( 2 );
108109

109110
var that = this;
110111

111112
this.element.datepicker( {
112113
open: function() {
113-
ok( true, "open event fired on open" );
114-
ok( that.widget.is( ":visible" ), "calendar open on open" );
114+
assert.ok( true, "open event fired on open" );
115+
assert.ok( that.widget.is( ":visible" ), "calendar open on open" );
115116
}
116117
} );
117118

118119
this.element.datepicker( "open" );
119120
} );
120121

121-
asyncTest( "select", function( assert ) {
122+
QUnit.test( "select", function( assert ) {
123+
var ready = assert.async();
122124
assert.expect( 4 );
123125

124126
var message = "",
125127
that = this;
126128

127129
this.element.datepicker( {
128130
select: function( event ) {
129-
ok( true, "select event fired " + message );
130-
equal(
131+
assert.ok( true, "select event fired " + message );
132+
assert.equal(
131133
event.originalEvent.type,
132134
"calendarselect",
133135
"select originalEvent " + message
@@ -169,7 +171,7 @@ asyncTest( "select", function( assert ) {
169171
setTimeout( function() {
170172
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } );
171173
that.element.datepicker( "close" );
172-
start();
174+
ready();
173175
}, 100 );
174176
}
175177

0 commit comments

Comments
 (0)