Skip to content

Commit 55b01ab

Browse files
committed
Date tests: Update to QUnit 2.x, shift to use no globals
1 parent 042eae9 commit 55b01ab

File tree

1 file changed

+57
-56
lines changed

1 file changed

+57
-56
lines changed

tests/unit/date/core.js

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,76 @@
11
define( [
2+
"qunit",
23
"jquery",
34
"./helper",
45
"ui/date"
5-
], function( $, testHelper ) {
6+
], function( QUnit, $, testHelper ) {
67

7-
module( "date: core" );
8+
QUnit.module( "date: core" );
89

910
var attributes = testHelper.getAttributes( "en" );
1011

11-
test( "Instantiation", function() {
12-
expect( 2 );
13-
ok( new $.ui.date( null, attributes ) instanceof $.ui.date, "constructor function" );
14-
ok( $.ui.date( null, attributes ) instanceof $.ui.date, "instantiation without new" );
12+
QUnit.test( "Instantiation", function( assert ) {
13+
assert.expect( 2 );
14+
assert.ok( new $.ui.date( null, attributes ) instanceof $.ui.date, "constructor function" );
15+
assert.ok( $.ui.date( null, attributes ) instanceof $.ui.date, "instantiation without new" );
1516
} );
1617

17-
test( "Check Sets and Gets", 4, function() {
18-
var date = $.ui.date( null, attributes );
19-
equal( date.setDay( 15 ).day(), 15, "Set day and retrieve" );
20-
equal( date.setFullDate( 2012, 9, 15 ).year(), 2012, "Set full date and retrieve year" );
21-
equal( date.month(), 9, "Set full date and retrieve month" );
22-
equal( date.day(), 15, "Set full date and retrieve day" );
18+
QUnit.test( "Check Sets and Gets", 4, function( assert ) {
19+
var date = $.ui.date( null, attributes );
20+
assert.equal( date.setDay( 15 ).day(), 15, "Set day and retrieve" );
21+
assert.equal( date.setFullDate( 2012, 9, 15 ).year(), 2012, "Set full date and retrieve year" );
22+
assert.equal( date.month(), 9, "Set full date and retrieve month" );
23+
assert.equal( date.day(), 15, "Set full date and retrieve day" );
2324

2425
// TODO Add setTime test
2526
} );
2627

27-
test( "Date Adjustments - Normal Use Cases", 10, function() {
28+
QUnit.test( "Date Adjustments - Normal Use Cases", 10, function( assert ) {
2829
var date = $.ui.date( null, attributes );
2930

3031
// Use October 15, 2012
3132
date.setFullDate( 2012, 9, 15 );
32-
equal( date.adjust( "D", 1 ).day(), 16, "Add 1 day" );
33-
equal( date.adjust( "D", -1 ).day(), 15, "Subtract 1 day" );
34-
equal( date.adjust( "M", 1 ).month(), 10, "Add 1 month" );
35-
equal( date.adjust( "M", -1 ).month(), 9, "Subtract 1 month" );
36-
equal( date.adjust( "Y", 1 ).year(), 2013, "Add 1 year" );
37-
equal( date.adjust( "Y", -1 ).year(), 2012, "Subtract 1 year" );
33+
assert.equal( date.adjust( "D", 1 ).day(), 16, "Add 1 day" );
34+
assert.equal( date.adjust( "D", -1 ).day(), 15, "Subtract 1 day" );
35+
assert.equal( date.adjust( "M", 1 ).month(), 10, "Add 1 month" );
36+
assert.equal( date.adjust( "M", -1 ).month(), 9, "Subtract 1 month" );
37+
assert.equal( date.adjust( "Y", 1 ).year(), 2013, "Add 1 year" );
38+
assert.equal( date.adjust( "Y", -1 ).year(), 2012, "Subtract 1 year" );
3839

3940
// Check changing one value impact another. Ex: Day impacts month
4041
// Use April 30th 2012
4142
date.setFullDate( 2012, 3, 30 );
42-
equal( date.adjust( "D", 1 ).month(), 4, "Add 1 day to change month from April to May" );
43-
equal( date.adjust( "D", -1 ).month(), 3, "Subtract 1 day to change month from May to April" );
43+
assert.equal( date.adjust( "D", 1 ).month(), 4, "Add 1 day to change month from April to May" );
44+
assert.equal( date.adjust( "D", -1 ).month(), 3, "Subtract 1 day to change month from May to April" );
4445

4546
// Use December 31st 2012
4647
date.setFullDate( 2012, 11, 31 );
47-
equal( date.adjust( "D", 1 ).year(), 2013, "Add 1 day to change year from 2012 to 2013" );
48-
equal( date.adjust( "D", -1 ).year(), 2012,
48+
assert.equal( date.adjust( "D", 1 ).year(), 2013, "Add 1 day to change year from 2012 to 2013" );
49+
assert.equal( date.adjust( "D", -1 ).year(), 2012,
4950
"Subtract 1 day to change month from 2013 to 2012" );
5051
} );
5152

52-
test( "Date Adjustments - Month Overflow Edge Cases", 2, function() {
53+
QUnit.test( "Date Adjustments - Month Overflow Edge Cases", 2, function( assert ) {
5354
var date = $.ui.date( null, attributes );
5455

5556
// Use May 31 2012
5657
date.setFullDate( 2012, 4, 31 );
57-
equal( date.adjust( "M", 1 ).day(), 30,
58+
assert.equal( date.adjust( "M", 1 ).day(), 30,
5859
"Add 1 month from May to June sets days to 30, last day in June (prevent Overflow)" );
59-
equal( date.adjust( "M", -1 ).day(), 30,
60+
assert.equal( date.adjust( "M", -1 ).day(), 30,
6061
"Subtract 1 month from June to May sets days to 30 in May" );
6162
} );
6263

63-
test( "Date Adjustments - Leap Year Edge Cases", 1, function() {
64+
QUnit.test( "Date Adjustments - Leap Year Edge Cases", 1, function( assert ) {
6465
var date = $.ui.date( null, attributes );
6566

6667
// Use February 29 2012 a Leap year
6768
date.setFullDate( 2012, 1, 29 );
68-
equal( date.adjust( "Y", 1 ).day(), 28,
69+
assert.equal( date.adjust( "Y", 1 ).day(), 28,
6970
"Feb 29 2012, add a year to convert to Feb 28, 2013" );
7071
} );
7172

72-
test( "List days of Week", 2, function() {
73+
QUnit.test( "List days of Week", 2, function( assert ) {
7374
var date = $.ui.date( null, attributes ),
7475
offset0 = [
7576
{ "fullname": "Sunday", "shortname": "Su" },
@@ -90,34 +91,34 @@ test( "List days of Week", 2, function() {
9091
{ "fullname": "Sonntag", "shortname": "So." }
9192
];
9293

93-
deepEqual( date.weekdays(), offset0, "Get weekdays with start of day on 0 (English)" );
94+
assert.deepEqual( date.weekdays(), offset0, "Get weekdays with start of day on 0 (English)" );
9495
date = $.ui.date( null, testHelper.getAttributes( "de" ) );
95-
deepEqual( date.weekdays(), offset1, "Get weekdays with start of day on 1 (Germany)" );
96+
assert.deepEqual( date.weekdays(), offset1, "Get weekdays with start of day on 1 (Germany)" );
9697
} );
9798

98-
test( "Days in Month", 3, function() {
99+
QUnit.test( "Days in Month", 3, function( assert ) {
99100
var date = $.ui.date( null, attributes );
100101
date.setFullDate( 2012, 1, 1 );
101-
equal( date.daysInMonth(), 29, "Leap Year implicit check for 29 days" );
102-
equal( date.daysInMonth( 2012, 1 ), 29, "Leap Year explicit check for 29 days" );
103-
equal( date.daysInMonth( 2011, 3 ), 30, "April has 30 days" );
102+
assert.equal( date.daysInMonth(), 29, "Leap Year implicit check for 29 days" );
103+
assert.equal( date.daysInMonth( 2012, 1 ), 29, "Leap Year explicit check for 29 days" );
104+
assert.equal( date.daysInMonth( 2011, 3 ), 30, "April has 30 days" );
104105
} );
105106

106-
test( "Month Name", 2, function() {
107+
QUnit.test( "Month Name", 2, function( assert ) {
107108
var date = $.ui.date( null, attributes );
108-
equal( date.setFullDate( 2012, 3, 1 ).monthName(), "April", "Month name return April (English)" );
109+
assert.equal( date.setFullDate( 2012, 3, 1 ).monthName(), "April", "Month name return April (English)" );
109110
date = $.ui.date( null, testHelper.getAttributes( "de" ) );
110-
equal( date.setFullDate( 2012, 2, 1 ).monthName(), "März", "Month name return March (German)" );
111+
assert.equal( date.setFullDate( 2012, 2, 1 ).monthName(), "März", "Month name return March (German)" );
111112
} );
112113

113-
test( "Clone", 2, function() {
114+
QUnit.test( "Clone", 2, function( assert ) {
114115
var date = $.ui.date( null, attributes ),
115116
date2 = date.clone();
116-
ok( date2, "Created cloned object" );
117-
notEqual( date.adjust( "Y", 1 ).year(), date2.year(), "Object manipulated independently" );
117+
assert.ok( date2, "Created cloned object" );
118+
assert.notEqual( date.adjust( "Y", 1 ).year(), date2.year(), "Object manipulated independently" );
118119
} );
119120

120-
test( "Days", 1, function() {
121+
QUnit.test( "Days", 1, function( assert ) {
121122

122123
// TODO Needs work
123124
var date = $.ui.date( null, attributes );
@@ -141,34 +142,34 @@ test( "Days", 1, function() {
141142
day.title = "A good day!";
142143
}
143144
};
144-
ok( date.days(), "Date days() returns" );
145+
assert.ok( date.days(), "Date days() returns" );
145146
} );
146147

147-
test( "Months", 5, function() {
148+
QUnit.test( "Months", 5, function( assert ) {
148149
var date = $.ui.date( new Date( 2015, 11 - 1, 15 ), attributes ),
149150
currentMonth = date.months( 1 )[ 0 ],
150151
nextMonth = date.months( 1 )[ 1 ];
151152

152-
ok( currentMonth.first, "Current month marked as first" );
153-
ok( !nextMonth.first, "Next month not marked as first" );
154-
ok( nextMonth.last, "Next month marked as last" );
153+
assert.ok( currentMonth.first, "Current month marked as first" );
154+
assert.ok( !nextMonth.first, "Next month not marked as first" );
155+
assert.ok( nextMonth.last, "Next month marked as last" );
155156

156-
equal( currentMonth.month(), 10, "Current month index is November" );
157-
equal( nextMonth.month(), 11, "Next month index is December" );
157+
assert.equal( currentMonth.month(), 10, "Current month index is November" );
158+
assert.equal( nextMonth.month(), 11, "Next month index is December" );
158159
} );
159160

160-
test( "Equal", 4, function() {
161+
QUnit.test( "Equal", 4, function( assert ) {
161162
var date = $.ui.date( null, attributes );
162163
date.setFullDate( 2012, 9, 16 );
163-
ok( date.equal( new Date( 2012, 9, 16 ) ), "Does date equal provide date" );
164-
ok( !date.equal( new Date( 2011, 9, 16 ) ), "Does date year not equal provide date" );
165-
ok( !date.equal( new Date( 2012, 8, 16 ) ), "Does date month not equal provide date" );
166-
ok( !date.equal( new Date( 2012, 9, 15 ) ), "Does date day not equal provide date" );
164+
assert.ok( date.equal( new Date( 2012, 9, 16 ) ), "Does date equal provide date" );
165+
assert.ok( !date.equal( new Date( 2011, 9, 16 ) ), "Does date year not equal provide date" );
166+
assert.ok( !date.equal( new Date( 2012, 8, 16 ) ), "Does date month not equal provide date" );
167+
assert.ok( !date.equal( new Date( 2012, 9, 15 ) ), "Does date day not equal provide date" );
167168
} );
168169

169-
test( "Date", 1, function() {
170+
QUnit.test( "Date", 1, function( assert ) {
170171
var date = $.ui.date( null, attributes );
171-
ok( date.date() instanceof Date, "Date returned" );
172+
assert.ok( date.date() instanceof Date, "Date returned" );
172173
} );
173174

174175
} );

0 commit comments

Comments
 (0)