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
22ff8e9e
Commit
22ff8e9e
authored
Jan 07, 2010
by
jeresig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added manipulation tests for setter function args.
parent
8fa9e9d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
175 additions
and
3 deletions
+175
-3
manipulation.js
test/unit/manipulation.js
+175
-3
No files found.
test/unit/manipulation.js
View file @
22ff8e9e
...
...
@@ -288,7 +288,68 @@ test("append(String|Element|Array<Element>|jQuery)", function() {
test
(
"append(Function)"
,
function
()
{
testAppend
(
functionReturningObj
);
})
});
test
(
"append(Function) with incoming value"
,
function
()
{
expect
(
12
);
var
defaultText
=
'Try them out:'
,
old
=
jQuery
(
"#first"
).
html
();
var
result
=
jQuery
(
'#first'
).
append
(
function
(
i
,
val
){
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
'<b>buga</b>'
;
});
equals
(
result
.
text
(),
defaultText
+
'buga'
,
'Check if text appending works'
);
var
select
=
jQuery
(
'#select3'
);
old
=
select
.
html
();
equals
(
select
.
append
(
function
(
i
,
val
){
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
'<option value="appendTest">Append Test</option>'
;
}).
find
(
'option:last-child'
).
attr
(
'value'
),
'appendTest'
,
'Appending html options to select element'
);
reset
();
var
expected
=
"This link has class=
\"
blog
\"
: Simon Willison's WeblogTry them out:"
;
old
=
jQuery
(
"#sap"
).
html
();
jQuery
(
'#sap'
).
append
(
function
(
i
,
val
){
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
document
.
getElementById
(
'first'
);
});
equals
(
expected
,
jQuery
(
'#sap'
).
text
(),
"Check for appending of element"
);
reset
();
expected
=
"This link has class=
\"
blog
\"
: Simon Willison's WeblogTry them out:Yahoo"
;
old
=
jQuery
(
"#sap"
).
html
();
jQuery
(
'#sap'
).
append
(
function
(
i
,
val
){
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
[
document
.
getElementById
(
'first'
),
document
.
getElementById
(
'yahoo'
)];
});
equals
(
expected
,
jQuery
(
'#sap'
).
text
(),
"Check for appending of array of elements"
);
reset
();
expected
=
"This link has class=
\"
blog
\"
: Simon Willison's WeblogYahooTry them out:"
;
old
=
jQuery
(
"#sap"
).
html
();
jQuery
(
'#sap'
).
append
(
function
(
i
,
val
){
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
jQuery
(
"#first, #yahoo"
);
});
equals
(
expected
,
jQuery
(
'#sap'
).
text
(),
"Check for appending of jQuery object"
);
reset
();
old
=
jQuery
(
"#sap"
).
html
();
jQuery
(
"#sap"
).
append
(
function
(
i
,
val
){
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
5
;
});
ok
(
jQuery
(
"#sap"
)[
0
].
innerHTML
.
match
(
/5$/
),
"Check for appending a number"
);
reset
();
});
test
(
"appendTo(String|Element|Array<Element>|jQuery)"
,
function
()
{
expect
(
12
);
...
...
@@ -362,7 +423,7 @@ var testPrepend = function(val) {
expected
=
"YahooTry them out:This link has class=
\"
blog
\"
: Simon Willison's Weblog"
;
jQuery
(
'#sap'
).
prepend
(
val
(
jQuery
(
"#first, #yahoo"
)
));
equals
(
expected
,
jQuery
(
'#sap'
).
text
(),
"Check for prepending of jQuery object"
);
}
}
;
test
(
"prepend(String|Element|Array<Element>|jQuery)"
,
function
()
{
testPrepend
(
bareObj
);
...
...
@@ -370,7 +431,58 @@ test("prepend(String|Element|Array<Element>|jQuery)", function() {
test
(
"prepend(Function)"
,
function
()
{
testPrepend
(
functionReturningObj
);
})
});
test
(
"prepend(Function) with incoming value"
,
function
()
{
expect
(
10
);
var
defaultText
=
'Try them out:'
,
old
=
jQuery
(
'#first'
).
html
();
var
result
=
jQuery
(
'#first'
).
prepend
(
function
(
i
,
val
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
'<b>buga</b>'
;
});
equals
(
result
.
text
(),
'buga'
+
defaultText
,
'Check if text prepending works'
);
old
=
jQuery
(
"#select3"
).
html
();
equals
(
jQuery
(
'#select3'
).
prepend
(
function
(
i
,
val
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
'<option value="prependTest">Prepend Test</option>'
;
}).
find
(
'option:first-child'
).
attr
(
'value'
),
'prependTest'
,
'Prepending html options to select element'
);
reset
();
var
expected
=
"Try them out:This link has class=
\"
blog
\"
: Simon Willison's Weblog"
;
old
=
jQuery
(
'#sap'
).
html
();
jQuery
(
'#sap'
).
prepend
(
function
(
i
,
val
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
document
.
getElementById
(
'first'
);
});
equals
(
expected
,
jQuery
(
'#sap'
).
text
(),
"Check for prepending of element"
);
reset
();
expected
=
"Try them out:YahooThis link has class=
\"
blog
\"
: Simon Willison's Weblog"
;
old
=
jQuery
(
'#sap'
).
html
();
jQuery
(
'#sap'
).
prepend
(
function
(
i
,
val
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
[
document
.
getElementById
(
'first'
),
document
.
getElementById
(
'yahoo'
)];
});
equals
(
expected
,
jQuery
(
'#sap'
).
text
(),
"Check for prepending of array of elements"
);
reset
();
expected
=
"YahooTry them out:This link has class=
\"
blog
\"
: Simon Willison's Weblog"
;
old
=
jQuery
(
'#sap'
).
html
();
jQuery
(
'#sap'
).
prepend
(
function
(
i
,
val
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
jQuery
(
"#first, #yahoo"
);
});
equals
(
expected
,
jQuery
(
'#sap'
).
text
(),
"Check for prepending of jQuery object"
);
});
test
(
"prependTo(String|Element|Array<Element>|jQuery)"
,
function
()
{
expect
(
6
);
...
...
@@ -714,6 +826,66 @@ test("html(Function)", function() {
testHtml
(
functionReturningObj
);
});
test
(
"html(Function) with incoming value"
,
function
()
{
expect
(
20
);
var
div
=
jQuery
(
"#main > div"
),
old
=
div
.
map
(
function
(){
return
jQuery
(
this
).
html
()
});
div
.
html
(
function
(
i
,
val
)
{
equals
(
val
,
old
[
i
],
"Make sure the incoming value is correct."
);
return
"<b>test</b>"
;
});
var
pass
=
true
;
div
.
each
(
function
(){
if
(
this
.
childNodes
.
length
!==
1
)
{
pass
=
false
;
}
})
ok
(
pass
,
"Set HTML"
);
reset
();
// using contents will get comments regular, text, and comment nodes
var
j
=
jQuery
(
"#nonnodes"
).
contents
();
old
=
j
.
map
(
function
(){
return
jQuery
(
this
).
html
();
});
j
.
html
(
function
(
i
,
val
)
{
equals
(
val
,
old
[
i
],
"Make sure the incoming value is correct."
);
return
"<b>bold</b>"
;
});
j
.
find
(
'b'
).
removeData
();
equals
(
j
.
html
().
replace
(
/ xmlns="
[^
"
]
+"/g
,
""
).
toLowerCase
(),
"<b>bold</b>"
,
"Check node,textnode,comment with html()"
);
var
$div
=
jQuery
(
'<div />'
);
equals
(
$div
.
html
(
function
(
i
,
val
)
{
equals
(
val
,
""
,
"Make sure the incoming value is correct."
);
return
5
;
}).
html
(),
'5'
,
'Setting a number as html'
);
equals
(
$div
.
html
(
function
(
i
,
val
)
{
equals
(
val
,
"5"
,
"Make sure the incoming value is correct."
);
return
0
;
}).
html
(),
'0'
,
'Setting a zero as html'
);
var
$div2
=
jQuery
(
'<div/>'
),
insert
=
"<div>hello1</div>"
;
equals
(
$div2
.
html
(
function
(
i
,
val
)
{
equals
(
val
,
""
,
"Make sure the incoming value is correct."
);
return
insert
;
}).
html
(),
insert
,
"Verify escaped insertion."
);
equals
(
$div2
.
html
(
function
(
i
,
val
)
{
equals
(
val
,
insert
,
"Make sure the incoming value is correct."
);
return
"x"
+
insert
;
}).
html
(),
"x"
+
insert
,
"Verify escaped insertion."
);
equals
(
$div2
.
html
(
function
(
i
,
val
)
{
equals
(
val
,
"x"
+
insert
,
"Make sure the incoming value is correct."
);
return
" "
+
insert
;
}).
html
(),
" "
+
insert
,
"Verify escaped insertion."
);
});
var
testRemove
=
function
(
method
)
{
expect
(
9
);
...
...
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