Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
81b094b2
Commit
81b094b2
authored
Nov 03, 2012
by
Richard Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No ticket: update test suite to pass QUnit globals check in most environments. Close gh-1016.
parent
80d45a69
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
196 additions
and
90 deletions
+196
-90
testrunner.js
test/data/testrunner.js
+7
-2
ajax.js
test/unit/ajax.js
+112
-15
attributes.js
test/unit/attributes.js
+5
-2
core.js
test/unit/core.js
+38
-51
event.js
test/unit/event.js
+2
-0
offset.js
test/unit/offset.js
+32
-20
No files found.
test/data/testrunner.js
View file @
81b094b2
...
@@ -3,6 +3,11 @@
...
@@ -3,6 +3,11 @@
*/
*/
jQuery
.
noConflict
();
jQuery
.
noConflict
();
// For checking globals pollution
window
[
jQuery
.
expando
]
=
undefined
;
// ...in Gecko
this
.
getInterface
=
this
.
getInterface
;
// Expose Sizzle for Sizzle's selector tests
// Expose Sizzle for Sizzle's selector tests
// We remove Sizzle's globalization in jQuery
// We remove Sizzle's globalization in jQuery
var
Sizzle
=
Sizzle
||
jQuery
.
find
;
var
Sizzle
=
Sizzle
||
jQuery
.
find
;
...
@@ -96,7 +101,7 @@ function testSubproject( label, url, risTests ) {
...
@@ -96,7 +101,7 @@ function testSubproject( label, url, risTests ) {
}
}
});
});
function
requireFixture
(
fn
Test
)
{
function
requireFixture
(
fn
)
{
return
function
()
{
return
function
()
{
if
(
!
fixtureReplaced
)
{
if
(
!
fixtureReplaced
)
{
// Make sure that we retrieved a fixture for the subproject
// Make sure that we retrieved a fixture for the subproject
...
@@ -124,7 +129,7 @@ function testSubproject( label, url, risTests ) {
...
@@ -124,7 +129,7 @@ function testSubproject( label, url, risTests ) {
fixtureReplaced
=
true
;
fixtureReplaced
=
true
;
}
}
fn
Test
.
apply
(
this
,
arguments
);
fn
.
apply
(
this
,
arguments
);
};
};
}
}
}
}
...
...
test/unit/ajax.js
View file @
81b094b2
This diff is collapsed.
Click to expand it.
test/unit/attributes.js
View file @
81b094b2
...
@@ -340,9 +340,12 @@ test( "attr(String, Object)", function() {
...
@@ -340,9 +340,12 @@ test( "attr(String, Object)", function() {
});
});
jQuery
.
each
(
[
window
,
document
,
obj
,
"#firstp"
],
function
(
i
,
elem
)
{
jQuery
.
each
(
[
window
,
document
,
obj
,
"#firstp"
],
function
(
i
,
elem
)
{
var
$elem
=
jQuery
(
elem
);
// use iframeCallback to avoid generating a new global when testing window
var
oldVal
=
elem
.
iframeCallback
,
$elem
=
jQuery
(
elem
);
strictEqual
(
$elem
.
attr
(
"nonexisting"
),
undefined
,
"attr works correctly for non existing attributes (bug #7500)."
);
strictEqual
(
$elem
.
attr
(
"nonexisting"
),
undefined
,
"attr works correctly for non existing attributes (bug #7500)."
);
equal
(
$elem
.
attr
(
"something"
,
"foo"
).
attr
(
"something"
),
"foo"
,
"attr falls back to prop on unsupported arguments"
);
equal
(
$elem
.
attr
(
"iframeCallback"
,
"foo"
).
attr
(
"iframeCallback"
),
"foo"
,
"attr falls back to prop on unsupported arguments"
);
elem
.
iframeCallback
=
oldVal
;
});
});
var
table
=
jQuery
(
"#table"
).
append
(
"<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"
),
var
table
=
jQuery
(
"#table"
).
append
(
"<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>"
),
...
...
test/unit/core.js
View file @
81b094b2
...
@@ -194,23 +194,18 @@ test( "selector state", function() {
...
@@ -194,23 +194,18 @@ test( "selector state", function() {
});
});
test
(
"globalEval"
,
function
()
{
test
(
"globalEval"
,
function
()
{
expect
(
3
);
expect
(
3
);
jQuery
.
globalEval
(
"var globalEvalTest = true;"
);
jQuery
.
globalEval
(
"globalEvalTest = 1;"
);
ok
(
window
.
globalEvalTest
,
"Test variable declarations are global"
);
equal
(
window
.
globalEvalTest
,
1
,
"Test variable assignments are global"
);
window
.
globalEvalTest
=
false
;
jQuery
.
globalEval
(
"globalEvalTest = true;"
);
jQuery
.
globalEval
(
"var globalEvalTest = 2;"
);
ok
(
window
.
globalEvalTest
,
"Test variable assignment
s are global"
);
equal
(
window
.
globalEvalTest
,
2
,
"Test variable declaration
s are global"
);
window
.
globalEvalTest
=
false
;
jQuery
.
globalEval
(
"this.globalEvalTest = 3;"
);
equal
(
window
.
globalEvalTest
,
3
,
"Test context (this) is the window object"
);
jQuery
.
globalEval
(
"this.globalEvalTest = true;"
);
jQuery
.
globalEval
(
"delete globalEvalTest;"
);
ok
(
window
.
globalEvalTest
,
"Test context (this) is the window object"
);
window
.
globalEvalTest
=
undefined
;
});
});
test
(
"noConflict"
,
function
()
{
test
(
"noConflict"
,
function
()
{
...
@@ -285,75 +280,67 @@ test("type", function() {
...
@@ -285,75 +280,67 @@ test("type", function() {
asyncTest
(
"isPlainObject"
,
function
()
{
asyncTest
(
"isPlainObject"
,
function
()
{
expect
(
15
);
expect
(
15
);
var
iframe
;
var
pass
,
iframe
,
doc
,
fn
=
function
()
{};
// The use case that we want to match
// The use case that we want to match
ok
(
jQuery
.
isPlainObject
({}),
"{}"
);
ok
(
jQuery
.
isPlainObject
({}),
"{}"
);
// Not objects shouldn't be matched
// Not objects shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
""
),
"string"
);
ok
(
!
jQuery
.
isPlainObject
(
""
),
"string"
);
ok
(
!
jQuery
.
isPlainObject
(
0
)
&&
!
jQuery
.
isPlainObject
(
1
),
"number"
);
ok
(
!
jQuery
.
isPlainObject
(
0
)
&&
!
jQuery
.
isPlainObject
(
1
),
"number"
);
ok
(
!
jQuery
.
isPlainObject
(
true
)
&&
!
jQuery
.
isPlainObject
(
false
),
"boolean"
);
ok
(
!
jQuery
.
isPlainObject
(
true
)
&&
!
jQuery
.
isPlainObject
(
false
),
"boolean"
);
ok
(
!
jQuery
.
isPlainObject
(
null
),
"null"
);
ok
(
!
jQuery
.
isPlainObject
(
null
),
"null"
);
ok
(
!
jQuery
.
isPlainObject
(
undefined
),
"undefined"
);
ok
(
!
jQuery
.
isPlainObject
(
undefined
),
"undefined"
);
// Arrays shouldn't be matched
// Arrays shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
([]),
"array"
);
ok
(
!
jQuery
.
isPlainObject
([]),
"array"
);
// Instantiated objects shouldn't be matched
// Instantiated objects shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
new
Date
()),
"new Date"
);
ok
(
!
jQuery
.
isPlainObject
(
new
Date
()),
"new Date"
);
var
fnplain
=
function
(){};
// Functions shouldn't be matched
// Functions shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
fnplain
),
"fn"
);
ok
(
!
jQuery
.
isPlainObject
(
fn
),
"fn"
);
/** @constructor */
var
fn
=
function
()
{};
// Again, instantiated objects shouldn't be matched
// Again, instantiated objects shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
new
fn
()),
"new fn (no methods)"
);
ok
(
!
jQuery
.
isPlainObject
(
new
fn
()),
"new fn (no methods)"
);
// Makes the function a little more realistic
// Makes the function a little more realistic
// (and harder to detect, incidentally)
// (and harder to detect, incidentally)
fn
.
prototype
[
"someMethod"
]
=
function
(){};
fn
.
prototype
[
"someMethod"
]
=
function
(){};
// Again, instantiated objects shouldn't be matched
// Again, instantiated objects shouldn't be matched
ok
(
!
jQuery
.
isPlainObject
(
new
fn
()),
"new fn"
);
ok
(
!
jQuery
.
isPlainObject
(
new
fn
()),
"new fn"
);
// DOM Element
// DOM Element
ok
(
!
jQuery
.
isPlainObject
(
document
.
createElement
(
"div"
)),
"DOM Element"
);
ok
(
!
jQuery
.
isPlainObject
(
document
.
createElement
(
"div"
)
),
"DOM Element"
);
// Window
// Window
ok
(
!
jQuery
.
isPlainObject
(
window
),
"window"
);
ok
(
!
jQuery
.
isPlainObject
(
window
),
"window"
);
pass
=
false
;
try
{
try
{
jQuery
.
isPlainObject
(
window
.
location
);
jQuery
.
isPlainObject
(
window
.
location
);
ok
(
true
,
"Does not throw exceptions on host objects"
);
pass
=
true
;
}
catch
(
e
)
{
}
catch
(
e
)
{}
ok
(
false
,
"Does not throw exceptions on host objects -- FAIL"
);
ok
(
pass
,
"Does not throw exceptions on host objects"
);
}
try
{
iframe
=
document
.
createElement
(
"iframe"
);
document
.
body
.
appendChild
(
iframe
);
window
.
iframeDone
=
function
(
otherObject
){
// Objects from other windows should be matched
// Objects from other windows should be matched
ok
(
jQuery
.
isPlainObject
(
new
otherObject
()),
"new otherObject"
);
window
.
iframeCallback
=
function
(
otherObject
,
detail
)
{
document
.
body
.
removeChild
(
iframe
);
window
.
iframeCallback
=
undefined
;
iframe
.
parentNode
.
removeChild
(
iframe
);
ok
(
jQuery
.
isPlainObject
(
new
otherObject
()),
"new otherObject"
+
(
detail
?
" - "
+
detail
:
""
)
);
start
();
start
();
};
};
var
doc
=
iframe
.
contentDocument
||
iframe
.
contentWindow
.
document
;
try
{
iframe
=
jQuery
(
"#qunit-fixture"
)[
0
].
appendChild
(
document
.
createElement
(
"iframe"
)
);
doc
=
iframe
.
contentDocument
||
iframe
.
contentWindow
.
document
;
doc
.
open
();
doc
.
open
();
doc
.
write
(
"<body onload='window.parent.iframe
Done
(Object);'>"
);
doc
.
write
(
"<body onload='window.parent.iframe
Callback
(Object);'>"
);
doc
.
close
();
doc
.
close
();
}
catch
(
e
)
{
}
catch
(
e
)
{
document
.
body
.
removeChild
(
iframe
);
window
.
iframeDone
(
Object
,
"iframes not supported"
);
ok
(
true
,
"new otherObject - iframes not supported"
);
start
();
}
}
});
});
...
...
test/unit/event.js
View file @
81b094b2
...
@@ -1208,6 +1208,8 @@ test("trigger(eventObject, [data], [fn])", function() {
...
@@ -1208,6 +1208,8 @@ test("trigger(eventObject, [data], [fn])", function() {
equal
(
event
.
isDefaultPrevented
(),
false
,
"default not prevented"
);
equal
(
event
.
isDefaultPrevented
(),
false
,
"default not prevented"
);
});
});
// Explicitly introduce global variable for oldIE so QUnit doesn't complain if checking globals
window
.
onclick
=
undefined
;
test
(
".trigger() bubbling on disconnected elements (#10489)"
,
function
()
{
test
(
".trigger() bubbling on disconnected elements (#10489)"
,
function
()
{
expect
(
2
);
expect
(
2
);
...
...
test/unit/offset.js
View file @
81b094b2
if
(
jQuery
.
fn
.
offset
)
{
(
function
(
)
{
module
(
"offset"
,
{
setup
:
function
()
{
if
(
!
jQuery
.
fn
.
offset
)
{
// force a scroll value on the main window
return
;
// this insures that the results will be wrong
}
// if the offset method is using the scroll offset
// of the parent window
var
supportsScroll
,
supportsFixedPosition
,
var
forceScroll
=
jQuery
(
"<div>"
).
css
({
"width"
:
2000
,
"height"
:
2000
});
forceScroll
=
jQuery
(
"<div/>"
).
css
({
width
:
2000
,
height
:
2000
}),
// this needs to be body, because #qunit-fixture is hidden and elements inside it don't have a scrollTop
checkSupport
=
function
()
{
forceScroll
.
appendTo
(
"body"
);
// Only run once
var
checkDiv
=
jQuery
(
"<div>"
).
appendTo
(
"#qunit-fixture"
)[
0
]
;
checkSupport
=
false
;
var
checkFixed
=
jQuery
(
"<div/>"
).
css
({
position
:
"fixed"
,
top
:
"20px"
}).
appendTo
(
"#qunit-fixture"
);
// Must append to body because #qunit-fixture is hidden and elements inside it don't have a scrollTop
forceScroll
.
appendTo
(
"body"
);
window
.
scrollTo
(
200
,
200
);
window
.
scrollTo
(
200
,
200
);
window
.
supportsScroll
=
(
document
.
documentElement
.
scrollTop
||
document
.
body
.
scrollTop
)
;
supportsScroll
=
document
.
documentElement
.
scrollTop
||
document
.
body
.
scrollTop
;
window
.
scrollTo
(
1
,
1
);
forceScroll
.
detach
(
);
checkDiv
.
style
.
position
=
"fixed"
;
// Safari subtracts parent border width here (which is 5px)
checkDiv
.
style
.
top
=
"20px"
;
supportsFixedPosition
=
checkFixed
[
0
].
offsetTop
===
20
||
checkFixed
[
0
].
offsetTop
===
15
;
// safari subtracts parent border width here which is 5px
checkFixed
.
remove
();
window
.
supportsFixedPosition
=
(
checkDiv
.
offsetTop
===
20
||
checkDiv
.
offsetTop
===
15
);
};
checkDiv
.
style
.
position
=
checkDiv
.
style
.
top
=
""
;
jQuery
(
checkDiv
).
remove
();
module
(
"offset"
,
{
setup
:
function
(){
forceScroll
.
remove
();
if
(
typeof
checkSupport
===
"function"
)
{
checkSupport
();
}
// Force a scroll value on the main window to ensure incorrect results
// if offset is using the scroll offset of the parent window
forceScroll
.
appendTo
(
"body"
);
window
.
scrollTo
(
1
,
1
);
forceScroll
.
detach
();
},
teardown
:
moduleTeardown
});
},
teardown
:
moduleTeardown
});
/*
/*
...
@@ -529,4 +541,4 @@ test("fractions (see #7730 and #7885)", function() {
...
@@ -529,4 +541,4 @@ test("fractions (see #7730 and #7885)", function() {
div
.
remove
();
div
.
remove
();
});
});
}
}
)();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment