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
13468aba
Commit
13468aba
authored
Jan 16, 2013
by
Richard Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No ticket: improve replaceWith testing
parent
d8690344
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
55 deletions
+35
-55
manipulation.js
test/unit/manipulation.js
+35
-55
No files found.
test/unit/manipulation.js
View file @
13468aba
...
@@ -1148,104 +1148,88 @@ test( "insertAfter(String|Element|Array<Element>|jQuery)", function() {
...
@@ -1148,104 +1148,88 @@ test( "insertAfter(String|Element|Array<Element>|jQuery)", function() {
var
testReplaceWith
=
function
(
val
)
{
var
testReplaceWith
=
function
(
val
)
{
expect
(
22
);
var
tmp
,
y
,
child
,
child2
,
set
,
non_existent
,
$div
,
expected
=
22
;
var
tmp
,
y
,
child
,
child2
,
set
,
non_existant
,
$div
;
expect
(
expected
)
;
jQuery
(
"#yahoo"
).
replaceWith
(
val
(
"<b id='replace'>buga</b>"
)
);
jQuery
(
"#yahoo"
).
replaceWith
(
val
(
"<b id='replace'>buga</b>"
)
);
ok
(
jQuery
(
"#replace"
)[
0
],
"Replace element with string"
);
ok
(
jQuery
(
"#replace"
)[
0
],
"Replace element with
element from
string"
);
ok
(
!
jQuery
(
"#yahoo"
)[
0
],
"Verify that original element is gone, after string"
);
ok
(
!
jQuery
(
"#yahoo"
)[
0
],
"Verify that original element is gone, after string"
);
QUnit
.
reset
();
jQuery
(
"#anchor2"
).
replaceWith
(
val
(
document
.
getElementById
(
"first"
))
);
jQuery
(
"#yahoo"
).
replaceWith
(
val
(
document
.
getElementById
(
"first"
)
));
ok
(
jQuery
(
"#first"
)[
0
],
"Replace element with element"
);
ok
(
jQuery
(
"#first"
)[
0
],
"Replace element with element"
);
ok
(
!
jQuery
(
"#
yahoo
"
)[
0
],
"Verify that original element is gone, after element"
);
ok
(
!
jQuery
(
"#
anchor2
"
)[
0
],
"Verify that original element is gone, after element"
);
QUnit
.
reset
();
jQuery
(
"#qunit-fixture"
).
append
(
"<div id='bar'><div id='baz'></div></div>"
);
jQuery
(
"#qunit-fixture"
).
append
(
"<div id='bar'><div id='baz'</div></div>"
);
jQuery
(
"#baz"
).
replaceWith
(
val
(
"Baz"
)
);
jQuery
(
"#baz"
).
replaceWith
(
"Baz"
);
equal
(
jQuery
(
"#bar"
).
text
(),
"Baz"
,
"Replace element with text"
);
equal
(
jQuery
(
"#bar"
).
text
(),
"Baz"
,
"Replace element with text"
);
ok
(
!
jQuery
(
"#baz"
)[
0
],
"Verify that original element is gone, after element"
);
ok
(
!
jQuery
(
"#baz"
)[
0
],
"Verify that original element is gone, after element"
);
QUnit
.
reset
();
jQuery
(
"#google"
).
replaceWith
(
val
([
document
.
getElementById
(
"first"
),
document
.
getElementById
(
"mark"
)
])
);
jQuery
(
"#yahoo"
).
replaceWith
(
val
([
document
.
getElementById
(
"first"
),
document
.
getElementById
(
"mark"
)
])
);
ok
(
jQuery
(
"#first"
)[
0
],
"Replace element with array of elements"
);
ok
(
jQuery
(
"#first"
)[
0
],
"Replace element with array of elements"
);
ok
(
jQuery
(
"#mark"
)[
0
],
"Replace element with array of elements"
);
ok
(
jQuery
(
"#mark"
)[
0
],
"Replace element with array of elements"
);
ok
(
!
jQuery
(
"#
yahoo
"
)[
0
],
"Verify that original element is gone, after array of elements"
);
ok
(
!
jQuery
(
"#
google
"
)[
0
],
"Verify that original element is gone, after array of elements"
);
QUnit
.
reset
();
jQuery
(
"#groups"
).
replaceWith
(
val
(
jQuery
(
"#mark, #first"
))
);
jQuery
(
"#yahoo"
).
replaceWith
(
val
(
jQuery
(
"#mark, #first"
))
);
ok
(
jQuery
(
"#first"
)[
0
],
"Replace element with set of elements"
);
ok
(
jQuery
(
"#first"
)[
0
],
"Replace element with set of elements"
);
ok
(
jQuery
(
"#mark"
)[
0
],
"Replace element with set of elements"
);
ok
(
jQuery
(
"#mark"
)[
0
],
"Replace element with set of elements"
);
ok
(
!
jQuery
(
"#
yahoo
"
)[
0
],
"Verify that original element is gone, after set of elements"
);
ok
(
!
jQuery
(
"#
groups
"
)[
0
],
"Verify that original element is gone, after set of elements"
);
QUnit
.
reset
();
tmp
=
jQuery
(
"<div/>"
).
appendTo
(
"body
"
).
click
(
function
()
{
tmp
=
jQuery
(
"<div/>"
).
appendTo
(
"#qunit-fixture
"
).
click
(
function
()
{
ok
(
true
,
"Newly bound click run."
);
ok
(
true
,
"Newly bound click run."
);
});
});
y
=
jQuery
(
"<div/>"
).
appendTo
(
"
body
"
).
click
(
function
()
{
y
=
jQuery
(
"<div/>"
).
appendTo
(
"
#qunit-fixture
"
).
click
(
function
()
{
ok
(
tru
e
,
"Previously bound click run."
);
ok
(
fals
e
,
"Previously bound click run."
);
});
});
child
=
y
.
append
(
"<b>test</b>"
).
find
(
"b"
).
click
(
function
()
{
child
=
y
.
append
(
"<b>test</b>"
).
find
(
"b"
).
click
(
function
()
{
ok
(
true
,
"Child bound click run."
);
ok
(
true
,
"Child bound click run."
);
return
false
;
return
false
;
});
});
y
.
replaceWith
(
tmp
);
y
.
replaceWith
(
val
(
tmp
)
);
tmp
.
click
();
tmp
.
click
();
y
.
click
();
// Shouldn't be run
y
.
click
();
// Shouldn't be run
child
.
click
();
// Shouldn't be run
child
.
click
();
// Shouldn't be run
tmp
.
remove
();
y
.
remove
();
child
.
remove
();
QUnit
.
reset
();
y
=
jQuery
(
"<div/>"
).
appendTo
(
"
body
"
).
click
(
function
()
{
y
=
jQuery
(
"<div/>"
).
appendTo
(
"
#qunit-fixture
"
).
click
(
function
()
{
ok
(
tru
e
,
"Previously bound click run."
);
ok
(
fals
e
,
"Previously bound click run."
);
});
});
child2
=
y
.
append
(
"<u>test</u>"
).
find
(
"u"
).
click
(
function
()
{
child2
=
y
.
append
(
"<u>test</u>"
).
find
(
"u"
).
click
(
function
()
{
ok
(
true
,
"Child 2 bound click run."
);
ok
(
true
,
"Child 2 bound click run."
);
return
false
;
return
false
;
});
});
y
.
replaceWith
(
child2
);
y
.
replaceWith
(
val
(
child2
)
);
child2
.
click
();
child2
.
click
();
y
.
remove
();
child2
.
remove
();
QUnit
.
reset
();
set
=
jQuery
(
"<div/>"
).
replaceWith
(
val
(
"<span>test</span>"
)
);
set
=
jQuery
(
"<div/>"
).
replaceWith
(
val
(
"<span>test</span>"
));
equal
(
set
[
0
].
nodeName
.
toLowerCase
(),
"div"
,
"No effect on a disconnected node."
);
equal
(
set
[
0
].
nodeName
.
toLowerCase
(),
"div"
,
"No effect on a disconnected node."
);
equal
(
set
.
length
,
1
,
"No effect on a disconnected node."
);
equal
(
set
.
length
,
1
,
"No effect on a disconnected node."
);
equal
(
set
[
0
].
childNodes
.
length
,
0
,
"No effect on a disconnected node."
);
equal
(
set
[
0
].
childNodes
.
length
,
0
,
"No effect on a disconnected node."
);
non_existant
=
jQuery
(
"#does-not-exist"
).
replaceWith
(
val
(
"<b>should not throw an error</b>"
)
);
equal
(
non_existant
.
length
,
0
,
"Length of non existant element."
);
$div
=
jQuery
(
"<div class='replacewith'></div>"
).
appendTo
(
"body"
);
non_existent
=
jQuery
(
"#does-not-exist"
).
replaceWith
(
val
(
"<b>should not throw an error</b>"
)
);
// TODO: Work on jQuery(...) inline script execution
equal
(
non_existent
.
length
,
0
,
"Length of non existent element."
);
//$div.replaceWith("<div class='replacewith'></div><script>" +
//"equal(jQuery('.replacewith').length, 1, 'Check number of elements in page.');" +
//"</script>");
equal
(
jQuery
(
".replacewith"
).
length
,
1
,
"Check number of elements in page."
);
jQuery
(
".replacewith"
).
remove
();
QUnit
.
reset
();
$div
=
jQuery
(
"<div class='replacewith'></div>"
).
appendTo
(
"#qunit-fixture"
);
$div
.
replaceWith
(
val
(
"<div class='replacewith'></div><script>"
+
"equal( jQuery('.replacewith').length, 1, 'Check number of elements in page.' );"
+
"</script>"
)
);
jQuery
(
"#qunit-fixture"
).
append
(
"<div id='replaceWith'></div>"
);
jQuery
(
"#qunit-fixture"
).
append
(
"<div id='replaceWith'></div>"
);
equal
(
jQuery
(
"#qunit-fixture"
).
find
(
"div[id=replaceWith]"
).
length
,
1
,
"Make sure only one div exists."
);
equal
(
jQuery
(
"#qunit-fixture"
).
find
(
"div[id=replaceWith]"
).
length
,
1
,
"Make sure only one div exists."
);
jQuery
(
"#replaceWith"
).
replaceWith
(
val
(
"<div id='replaceWith'></div>"
)
);
jQuery
(
"#replaceWith"
).
replaceWith
(
val
(
"<div id='replaceWith'></div>"
)
);
equal
(
jQuery
(
"#qunit-fixture"
).
find
(
"div[id=replaceWith]"
).
length
,
1
,
"Make sure only one div exists."
);
equal
(
jQuery
(
"#qunit-fixture"
).
find
(
"div[id=replaceWith]"
).
length
,
1
,
"Make sure only one div exists after replacement."
);
jQuery
(
"#replaceWith"
).
replaceWith
(
val
(
"<div id='replaceWith'></div>"
)
);
jQuery
(
"#replaceWith"
).
replaceWith
(
val
(
"<div id='replaceWith'></div>"
)
);
equal
(
jQuery
(
"#qunit-fixture"
).
find
(
"div[id=replaceWith]"
).
length
,
1
,
"Make sure only one div exists."
);
equal
(
jQuery
(
"#qunit-fixture"
).
find
(
"div[id=replaceWith]"
).
length
,
1
,
"Make sure only one div exists after subsequent replacement."
);
return
expected
;
};
};
test
(
"replaceWith(String|Element|Array<Element>|jQuery)"
,
function
()
{
test
(
"replaceWith(String|Element|Array<Element>|jQuery)"
,
function
()
{
...
@@ -1253,17 +1237,13 @@ test( "replaceWith(String|Element|Array<Element>|jQuery)", function() {
...
@@ -1253,17 +1237,13 @@ test( "replaceWith(String|Element|Array<Element>|jQuery)", function() {
});
});
test
(
"replaceWith(Function)"
,
function
()
{
test
(
"replaceWith(Function)"
,
function
()
{
testReplaceWith
(
manipulationFunctionReturningObj
);
expect
(
testReplaceWith
(
manipulationFunctionReturningObj
)
+
1
);
expect
(
23
);
var
y
=
jQuery
(
"#
yah
oo"
)[
0
];
var
y
=
jQuery
(
"#
f
oo"
)[
0
];
jQuery
(
y
).
replaceWith
(
function
()
{
jQuery
(
y
).
replaceWith
(
function
()
{
equal
(
this
,
y
,
"Make sure the context is coming in correctly."
);
equal
(
this
,
y
,
"Make sure the context is coming in correctly."
);
});
});
QUnit
.
reset
();
});
});
test
(
"replaceWith(string) for more than one element"
,
function
()
{
test
(
"replaceWith(string) for more than one element"
,
function
()
{
...
...
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