1
1
define ( [
2
- "jquery"
3
- ] , function ( $ ) {
2
+ "qunit" ,
3
+ "jquery" ] ,
4
+ function ( QUnit , $ ) {
4
5
5
6
var exports = { } ;
6
7
7
8
function testWidgetDefaults ( widget , defaults ) {
8
9
var pluginDefaults = $ . ui [ widget ] . prototype . options ;
9
10
10
11
// Ensure that all defaults have the correct value
11
- test ( "defined defaults" , function ( ) {
12
+ QUnit . test ( "defined defaults" , function ( assert ) {
12
13
var count = 0 ;
13
14
$ . each ( defaults , function ( key , val ) {
14
- expect ( ++ count ) ;
15
+ assert . expect ( ++ count ) ;
15
16
if ( $ . isFunction ( val ) ) {
16
- ok ( $ . isFunction ( pluginDefaults [ key ] ) , key ) ;
17
+ assert . ok ( $ . isFunction ( pluginDefaults [ key ] ) , key ) ;
17
18
return ;
18
19
}
19
- deepEqual ( pluginDefaults [ key ] , val , key ) ;
20
+ assert . deepEqual ( pluginDefaults [ key ] , val , key ) ;
20
21
} ) ;
21
22
} ) ;
22
23
23
24
// Ensure that all defaults were tested
24
- test ( "tested defaults" , function ( ) {
25
+ QUnit . test ( "tested defaults" , function ( assert ) {
25
26
var count = 0 ;
26
27
$ . each ( pluginDefaults , function ( key ) {
27
- expect ( ++ count ) ;
28
- ok ( key in defaults , key ) ;
28
+ assert . expect ( ++ count ) ;
29
+ assert . ok ( key in defaults , key ) ;
29
30
} ) ;
30
31
} ) ;
31
32
}
32
33
33
34
function testWidgetOverrides ( widget ) {
34
35
if ( $ . uiBackCompat === false ) {
35
- test ( "$.widget overrides" , function ( ) {
36
- expect ( 4 ) ;
36
+ QUnit . test ( "$.widget overrides" , function ( assert ) {
37
+ assert . expect ( 4 ) ;
37
38
$ . each ( [
38
39
"_createWidget" ,
39
40
"destroy" ,
40
41
"option" ,
41
42
"_trigger"
42
43
] , function ( i , method ) {
43
- strictEqual ( $ . ui [ widget ] . prototype [ method ] ,
44
+ assert . strictEqual ( $ . ui [ widget ] . prototype [ method ] ,
44
45
$ . Widget . prototype [ method ] , "should not override " + method ) ;
45
46
} ) ;
46
47
} ) ;
47
48
}
48
49
}
49
50
50
51
function testBasicUsage ( widget ) {
51
- test ( "basic usage" , function ( ) {
52
- expect ( 3 ) ;
52
+ QUnit . test ( "basic usage" , function ( assert ) {
53
+ assert . expect ( 3 ) ;
53
54
54
55
var defaultElement = $ . ui [ widget ] . prototype . defaultElement ;
55
56
$ ( defaultElement ) . appendTo ( "body" ) [ widget ] ( ) . remove ( ) ;
56
- ok ( true , "initialized on element" ) ;
57
+ assert . ok ( true , "initialized on element" ) ;
57
58
58
59
$ ( defaultElement ) [ widget ] ( ) . remove ( ) ;
59
- ok ( true , "initialized on disconnected DOMElement - never connected" ) ;
60
+ assert . ok ( true , "initialized on disconnected DOMElement - never connected" ) ;
60
61
61
62
// Ensure manipulating removed elements works (#3664)
62
63
$ ( defaultElement ) . appendTo ( "body" ) . remove ( ) [ widget ] ( ) . remove ( ) ;
63
- ok ( true , "initialized on disconnected DOMElement - removed" ) ;
64
+ assert . ok ( true , "initialized on disconnected DOMElement - removed" ) ;
64
65
} ) ;
65
66
}
66
67
67
68
exports . testWidget = function ( widget , settings ) {
68
- module ( widget + ": common widget" ) ;
69
+ QUnit . module ( widget + ": common widget" ) ;
69
70
70
71
exports . testJshint ( "/widgets/" + widget ) ;
71
72
testWidgetDefaults ( widget , settings . defaults ) ;
72
73
testWidgetOverrides ( widget ) ;
73
74
if ( ! settings . noDefaultElement ) {
74
75
testBasicUsage ( widget ) ;
75
76
}
76
- test ( "version" , function ( ) {
77
- expect ( 1 ) ;
78
- ok ( "version" in $ . ui [ widget ] . prototype , "version property exists" ) ;
77
+ QUnit . test ( "version" , function ( assert ) {
78
+ assert . expect ( 1 ) ;
79
+ assert . ok ( "version" in $ . ui [ widget ] . prototype , "version property exists" ) ;
79
80
} ) ;
80
81
} ;
81
82
@@ -87,9 +88,10 @@ exports.testJshint = function( module ) {
87
88
return ;
88
89
}
89
90
90
- asyncTest ( "JSHint" , function ( ) {
91
- require ( [ "jshint" ] , function ( ) {
92
- expect ( 1 ) ;
91
+ QUnit . test ( "JSHint" , function ( assert ) {
92
+ var ready = assert . async ( ) ;
93
+ require ( [ "jshint" ] , function ( ) {
94
+ assert . expect ( 1 ) ;
93
95
94
96
$ . when (
95
97
$ . ajax ( {
@@ -119,15 +121,15 @@ exports.testJshint = function( module ) {
119
121
return "[L" + error . line + ":C" + error . character + "] " +
120
122
error . reason + "\n" + error . evidence + "\n" ;
121
123
} ) . join ( "\n" ) ;
122
- ok ( passed , errors ) ;
123
- start ( ) ;
124
+ assert . ok ( passed , errors ) ;
125
+ ready ( ) ;
124
126
} )
125
127
. fail ( function ( hintError , srcError ) {
126
- ok ( false , "error loading source: " + ( hintError || srcError ) . statusText ) ;
127
- start ( ) ;
128
+ assert . ok ( false , "error loading source: " + ( hintError || srcError ) . statusText ) ;
129
+ ready ( ) ;
128
130
} ) ;
129
131
} ) ;
130
- } ) ;
132
+ } ) ;
131
133
} ;
132
134
133
135
return exports ;
0 commit comments