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
f126f1ce
Commit
f126f1ce
authored
Jan 07, 2010
by
jeresig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for attribute function setters.
parent
21e15219
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
141 additions
and
9 deletions
+141
-9
attributes.js
test/unit/attributes.js
+141
-9
No files found.
test/unit/attributes.js
View file @
f126f1ce
...
@@ -292,6 +292,11 @@ test("attr('tabindex', value)", function() {
...
@@ -292,6 +292,11 @@ test("attr('tabindex', value)", function() {
equals
(
element
.
attr
(
'tabindex'
),
-
1
,
'set negative tabindex'
);
equals
(
element
.
attr
(
'tabindex'
),
-
1
,
'set negative tabindex'
);
});
});
test
(
"removeAttr(String)"
,
function
()
{
expect
(
1
);
equals
(
jQuery
(
'#mark'
).
removeAttr
(
"class"
)[
0
].
className
,
""
,
"remove class"
);
});
test
(
"val()"
,
function
()
{
test
(
"val()"
,
function
()
{
expect
(
17
);
expect
(
17
);
...
@@ -378,6 +383,57 @@ test("val(Function)", function() {
...
@@ -378,6 +383,57 @@ test("val(Function)", function() {
testVal
(
functionReturningObj
);
testVal
(
functionReturningObj
);
})
})
test
(
"val(Function) with incoming value"
,
function
()
{
expect
(
10
);
var
oldVal
=
jQuery
(
"#text1"
).
val
();
jQuery
(
"#text1"
).
val
(
function
(
i
,
val
)
{
equals
(
val
,
oldVal
,
"Make sure the incoming value is correct."
);
return
"test"
;
});
equals
(
document
.
getElementById
(
'text1'
).
value
,
"test"
,
"Check for modified (via val(String)) value of input element"
);
oldVal
=
jQuery
(
"#text1"
).
val
();
jQuery
(
"#text1"
).
val
(
function
(
i
,
val
)
{
equals
(
val
,
oldVal
,
"Make sure the incoming value is correct."
);
return
67
;
});
equals
(
document
.
getElementById
(
'text1'
).
value
,
"67"
,
"Check for modified (via val(Number)) value of input element"
);
oldVal
=
jQuery
(
"#select1"
).
val
();
jQuery
(
"#select1"
).
val
(
function
(
i
,
val
)
{
equals
(
val
,
oldVal
,
"Make sure the incoming value is correct."
);
return
"3"
;
});
equals
(
jQuery
(
"#select1"
).
val
(),
"3"
,
"Check for modified (via val(String)) value of select element"
);
oldVal
=
jQuery
(
"#select1"
).
val
();
jQuery
(
"#select1"
).
val
(
function
(
i
,
val
)
{
equals
(
val
,
oldVal
,
"Make sure the incoming value is correct."
);
return
2
;
});
equals
(
jQuery
(
"#select1"
).
val
(),
"2"
,
"Check for modified (via val(Number)) value of select element"
);
jQuery
(
"#select1"
).
append
(
"<option value='4'>four</option>"
);
oldVal
=
jQuery
(
"#select1"
).
val
();
jQuery
(
"#select1"
).
val
(
function
(
i
,
val
)
{
equals
(
val
,
oldVal
,
"Make sure the incoming value is correct."
);
return
4
;
});
equals
(
jQuery
(
"#select1"
).
val
(),
"4"
,
"Should be possible to set the val() to a newly created option"
);
});
var
testAddClass
=
function
(
valueObj
)
{
var
testAddClass
=
function
(
valueObj
)
{
expect
(
2
);
expect
(
2
);
var
div
=
jQuery
(
"div"
);
var
div
=
jQuery
(
"div"
);
...
@@ -402,6 +458,25 @@ test("addClass(Function)", function() {
...
@@ -402,6 +458,25 @@ test("addClass(Function)", function() {
testAddClass
(
functionReturningObj
);
testAddClass
(
functionReturningObj
);
});
});
test
(
"addClass(Function) with incoming value"
,
function
()
{
expect
(
39
);
var
div
=
jQuery
(
"div"
),
old
=
div
.
map
(
function
(){
return
jQuery
(
this
).
attr
(
"class"
);
});
div
.
addClass
(
function
(
i
,
val
)
{
equals
(
val
,
old
[
i
],
"Make sure the incoming value is correct."
);
return
"test"
;
});
var
pass
=
true
;
for
(
var
i
=
0
;
i
<
div
.
size
();
i
++
)
{
if
(
div
.
get
(
i
).
className
.
indexOf
(
"test"
)
==
-
1
)
pass
=
false
;
}
ok
(
pass
,
"Add Class"
);
});
var
testRemoveClass
=
function
(
valueObj
)
{
var
testRemoveClass
=
function
(
valueObj
)
{
expect
(
5
);
expect
(
5
);
...
@@ -443,6 +518,23 @@ test("removeClass(Function) - simple", function() {
...
@@ -443,6 +518,23 @@ test("removeClass(Function) - simple", function() {
testRemoveClass
(
functionReturningObj
);
testRemoveClass
(
functionReturningObj
);
});
});
test
(
"removeClass(Function) with incoming value"
,
function
()
{
expect
(
39
);
var
$divs
=
jQuery
(
'div'
).
addClass
(
"test"
),
old
=
$divs
.
map
(
function
(){
return
jQuery
(
this
).
attr
(
"class"
);
});
$divs
.
removeClass
(
function
(
i
,
val
)
{
equals
(
val
,
old
[
i
],
"Make sure the incoming value is correct."
);
return
"test"
;
});
ok
(
!
$divs
.
is
(
'.test'
),
"Remove Class"
);
reset
();
});
var
testToggleClass
=
function
(
valueObj
)
{
var
testToggleClass
=
function
(
valueObj
)
{
expect
(
17
);
expect
(
17
);
...
@@ -503,17 +595,57 @@ test("toggleClass(Function[, boolean])", function() {
...
@@ -503,17 +595,57 @@ test("toggleClass(Function[, boolean])", function() {
testToggleClass
(
functionReturningObj
);
testToggleClass
(
functionReturningObj
);
});
});
var
testRemoveAttr
=
function
(
valueObj
)
{
test
(
"toggleClass(Fucntion[, boolean]) with incoming value"
,
function
()
{
expect
(
1
);
expect
(
14
);
equals
(
jQuery
(
'#mark'
).
removeAttr
(
valueObj
(
"class"
)
)[
0
].
className
,
""
,
"remove class"
);
};
test
(
"removeAttr(String)"
,
function
()
{
var
e
=
jQuery
(
"#firstp"
),
old
=
e
.
attr
(
"class"
);
testRemoveAttr
(
bareObj
);
ok
(
!
e
.
is
(
".test"
),
"Assert class not present"
);
});
e
.
toggleClass
(
function
(
i
,
val
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
"test"
;
});
ok
(
e
.
is
(
".test"
),
"Assert class present"
);
old
=
e
.
attr
(
"class"
);
e
.
toggleClass
(
function
(
i
,
val
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
return
"test"
;
});
ok
(
!
e
.
is
(
".test"
),
"Assert class not present"
);
old
=
e
.
attr
(
"class"
);
test
(
"removeAttr(Function)"
,
function
()
{
// class name with a boolean
testRemoveAttr
(
functionReturningObj
);
e
.
toggleClass
(
function
(
i
,
val
,
state
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
equals
(
state
,
false
,
"Make sure that the state is passed in."
);
return
"test"
;
},
false
);
ok
(
!
e
.
is
(
".test"
),
"Assert class not present"
);
old
=
e
.
attr
(
"class"
);
e
.
toggleClass
(
function
(
i
,
val
,
state
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
equals
(
state
,
true
,
"Make sure that the state is passed in."
);
return
"test"
;
},
true
);
ok
(
e
.
is
(
".test"
),
"Assert class present"
);
old
=
e
.
attr
(
"class"
);
e
.
toggleClass
(
function
(
i
,
val
,
state
)
{
equals
(
val
,
old
,
"Make sure the incoming value is correct."
);
equals
(
state
,
false
,
"Make sure that the state is passed in."
);
return
"test"
;
},
false
);
ok
(
!
e
.
is
(
".test"
),
"Assert class not present"
);
// Cleanup
e
.
removeClass
(
"test"
);
e
.
removeData
(
'__className__'
);
});
});
test
(
"addClass, removeClass, hasClass"
,
function
()
{
test
(
"addClass, removeClass, hasClass"
,
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