Skip to content

Commit e089b1d

Browse files
committed
Checkboxradio: Shift to use no globals
1 parent fd1c236 commit e089b1d

File tree

4 files changed

+98
-91
lines changed

4 files changed

+98
-91
lines changed

tests/unit/checkboxradio/core.js

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

6-
module( "Checkboxradio: core" );
7+
QUnit.module( "Checkboxradio: core" );
78

8-
test( "Checkbox - Initial class structure", function( assert ) {
9-
expect( 2 );
9+
QUnit.test( "Checkbox - Initial class structure", function( assert ) {
10+
assert.expect( 2 );
1011
var input = $( "#check" ),
1112
label = $( "label[for=check]" );
1213

@@ -15,8 +16,8 @@ test( "Checkbox - Initial class structure", function( assert ) {
1516
assert.hasClasses( label, "ui-button ui-widget ui-checkboxradio-label ui-corner-all" );
1617
} );
1718

18-
test( "Radios - Initial class structure", function( assert ) {
19-
expect( 6 );
19+
QUnit.test( "Radios - Initial class structure", function( assert ) {
20+
assert.expect( 6 );
2021
var inputs = $( "#radio0 input" ),
2122
labels = $( "#radio0 label" );
2223

@@ -29,12 +30,13 @@ test( "Radios - Initial class structure", function( assert ) {
2930
} );
3031
} );
3132

32-
asyncTest( "Ensure checked after single click on checkbox label button", function( assert ) {
33-
expect( 2 );
33+
QUnit.test( "Ensure checked after single click on checkbox label button", function( assert ) {
34+
var ready = assert.async();
35+
assert.expect( 2 );
3436

3537
$( "#check2" ).checkboxradio().change( function() {
3638
var label = $( this ).checkboxradio( "widget" );
37-
ok( this.checked, "checked ok" );
39+
assert.ok( this.checked, "checked ok" );
3840

3941
assert.hasClasses( label, "ui-state-active" );
4042
} );
@@ -45,21 +47,21 @@ asyncTest( "Ensure checked after single click on checkbox label button", functio
4547
// tracked down, this delay will have to do.
4648
setTimeout( function() {
4749
$( "#check2" ).checkboxradio( "widget" ).simulate( "click" );
48-
start();
50+
ready();
4951
} );
5052
} );
5153

52-
test( "Handle form association via form attribute", function( assert ) {
53-
expect( 4 );
54+
QUnit.test( "Handle form association via form attribute", function( assert ) {
55+
assert.expect( 4 );
5456

5557
var radio1 = $( "#crazy-form-1" ).checkboxradio();
5658
var radio1Label = radio1.checkboxradio( "widget" );
5759
var radio2 = $( "#crazy-form-2" ).checkboxradio();
5860
var radio2Label = radio2.checkboxradio( "widget" );
5961

6062
radio2.change( function() {
61-
ok( this.checked, "#2 checked" );
62-
ok( !radio1[ 0 ].checked, "#1 not checked" );
63+
assert.ok( this.checked, "#2 checked" );
64+
assert.ok( !radio1[ 0 ].checked, "#1 not checked" );
6365

6466
assert.hasClasses( radio2Label, "ui-state-active" );
6567
assert.lacksClasses( radio1Label, "ui-state-active" );
@@ -68,8 +70,8 @@ test( "Handle form association via form attribute", function( assert ) {
6870
radio2Label.simulate( "click" );
6971
} );
7072

71-
test( "Checkbox creation requires a label, and finds it in all cases", function( assert ) {
72-
expect( 7 );
73+
QUnit.test( "Checkbox creation requires a label, and finds it in all cases", function( assert ) {
74+
assert.expect( 7 );
7375
var groups = [
7476
"<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>",
7577
"<span><input type='checkbox' id='t7092b'><label for='t7092b'></label></span>",
@@ -88,8 +90,8 @@ test( "Checkbox creation requires a label, and finds it in all cases", function(
8890
} );
8991
} );
9092

91-
test( "Calling checkboxradio on an unsupported element throws an error", function( assert ) {
92-
expect( 2 );
93+
QUnit.test( "Calling checkboxradio on an unsupported element throws an error", function( assert ) {
94+
assert.expect( 2 );
9395

9496
var errorMessage =
9597
"Can't create checkboxradio on element.nodeName=div and element.type=undefined";
@@ -117,8 +119,8 @@ test( "Calling checkboxradio on an unsupported element throws an error", functio
117119
);
118120
} );
119121

120-
test( "Calling checkboxradio on an input with no label throws an error", function( assert ) {
121-
expect( 1 );
122+
QUnit.test( "Calling checkboxradio on an input with no label throws an error", function( assert ) {
123+
assert.expect( 1 );
122124

123125
var errorMessage = "No label found for checkboxradio widget";
124126
var error = new Error( errorMessage );

tests/unit/checkboxradio/events.js

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

6-
module( "Checkboxradio: events" );
7+
QUnit.module( "Checkboxradio: events" );
78

8-
asyncTest(
9+
QUnit.test(
910
"Resetting a checkbox's form should refresh the visual state of the checkbox",
1011
function( assert ) {
11-
expect( 2 );
12+
var ready = assert.async();
13+
assert.expect( 2 );
1214
var form = $( "<form>" +
1315
"<label for='c1'></label><input id='c1' type='checkbox' checked>" +
1416
"</form>" ),
@@ -22,20 +24,21 @@ asyncTest(
2224

2325
setTimeout( function() {
2426
assert.hasClasses( widget, "ui-state-active" );
25-
start();
27+
ready();
2628
}, 1 );
2729
}
2830
);
2931

30-
asyncTest( "Checkbox shows focus when using keyboard navigation", function( assert ) {
31-
expect( 2 );
32+
QUnit.test( "Checkbox shows focus when using keyboard navigation", function( assert ) {
33+
var ready = assert.async();
34+
assert.expect( 2 );
3235
var check = $( "#check" ).checkboxradio(),
3336
label = $( "label[for='check']" );
3437
assert.lacksClasses( label, "ui-state-focus" );
3538
check.focus();
3639
setTimeout( function() {
3740
assert.hasClasses( label, "ui-state-focus" );
38-
start();
41+
ready();
3942
} );
4043
} );
4144

tests/unit/checkboxradio/methods.js

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

6-
module( "Checkboxradio: methods" );
7+
QUnit.module( "Checkboxradio: methods" );
78

89
$.each( [ "checkbox", "radio" ], function( index, value ) {
9-
test( value + ": refresh", function( assert ) {
10+
QUnit.test( value + ": refresh", function( assert ) {
1011
var widget, icon,
1112
checkbox = value === "checkbox",
1213
input = $( "#" + value + "-method-refresh" );
1314

14-
expect( checkbox ? 11 : 8 );
15+
assert.expect( checkbox ? 11 : 8 );
1516

1617
input.checkboxradio();
1718

1819
widget = input.checkboxradio( "widget" );
1920
icon = widget.find( ".ui-icon" );
20-
strictEqual( icon.length, 1,
21+
assert.strictEqual( icon.length, 1,
2122
"There is initally one icon" );
2223

2324
icon.remove();
2425
input.checkboxradio( "refresh" );
2526
icon = widget.find( ".ui-icon" );
26-
strictEqual( icon.length, 1,
27+
assert.strictEqual( icon.length, 1,
2728
"Icon is recreated on refresh if absent" );
2829
assert.hasClasses( icon, "ui-icon-blank" );
2930
if ( checkbox ) {
@@ -48,49 +49,49 @@ $.each( [ "checkbox", "radio" ], function( index, value ) {
4849
assert.lacksClasses( widget, "ui-checkboxradio-checked" );
4950
} );
5051

51-
test( value + ": destroy", function( assert ) {
52-
expect( 1 );
52+
QUnit.test( value + ": destroy", function( assert ) {
53+
assert.expect( 1 );
5354
assert.domEqual( "#" + value + "-method-destroy", function() {
5455
$( "#" + value + "-method-destroy" ).checkboxradio().checkboxradio( "destroy" );
5556
} );
5657
} );
5758

58-
test( value + ": disable / enable", function( assert ) {
59-
expect( 4 );
59+
QUnit.test( value + ": disable / enable", function( assert ) {
60+
assert.expect( 4 );
6061
var input = $( "#" + value + "-method-disable" ),
6162
widget = input.checkboxradio().checkboxradio( "widget" );
6263

6364
input.checkboxradio( "disable" );
6465
assert.hasClasses( widget, "ui-state-disabled" );
65-
strictEqual( input.is( ":disabled" ), true,
66+
assert.strictEqual( input.is( ":disabled" ), true,
6667
value + " is disabled when disable is called" );
6768

6869
input.checkboxradio( "enable" );
6970
assert.lacksClasses( widget, "ui-state-disabled" );
70-
strictEqual( input.is( ":disabled" ), false,
71+
assert.strictEqual( input.is( ":disabled" ), false,
7172
value + " has disabled prop removed when enable is called" );
7273
} );
7374

74-
test( value + ": widget returns the label", function() {
75-
expect( 1 );
75+
QUnit.test( value + ": widget returns the label", function( assert ) {
76+
assert.expect( 1 );
7677

7778
var input = $( "#" + value + "-method-refresh" ),
7879
label = $( "#" + value + "-method-refresh-label" );
7980

8081
input.checkboxradio();
81-
strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
82+
assert.strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
8283
"widget method returns label" );
8384
} );
8485
} );
8586

86-
test( "Input wrapped in a label preserved on refresh", function() {
87+
QUnit.test( "Input wrapped in a label preserved on refresh", function( assert ) {
8788
var input = $( "#label-with-no-for" ).checkboxradio(),
8889
element = input.checkboxradio( "widget" );
8990

90-
expect( 1 );
91+
assert.expect( 1 );
9192

9293
input.checkboxradio( "refresh" );
93-
strictEqual( input.parent()[ 0 ], element[ 0 ], "Input preserved" );
94+
assert.strictEqual( input.parent()[ 0 ], element[ 0 ], "Input preserved" );
9495
} );
9596

9697
} );

0 commit comments

Comments
 (0)