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
eced38a3
Commit
eced38a3
authored
Jan 08, 2009
by
Ariel Flesler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testrunner: refactored unbind's tests. Including one for #3538, passing since last commit.
parent
6898cd6d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
37 deletions
+66
-37
event.js
test/unit/event.js
+66
-37
No files found.
test/unit/event.js
View file @
eced38a3
...
@@ -166,6 +166,72 @@ test("bind(), multi-namespaced events", function() {
...
@@ -166,6 +166,72 @@ test("bind(), multi-namespaced events", function() {
jQuery
(
"#firstp"
).
trigger
(
"custom"
);
jQuery
(
"#firstp"
).
trigger
(
"custom"
);
});
});
test
(
"unbind(type)"
,
function
()
{
expect
(
0
);
var
$elem
=
jQuery
(
"#firstp"
),
message
;
function
error
(){
ok
(
false
,
message
);
}
message
=
"unbind passing function"
;
$elem
.
bind
(
'error'
,
error
).
unbind
(
'error'
,
error
).
triggerHandler
(
'error'
);
message
=
"unbind all from event"
;
$elem
.
bind
(
'error'
,
error
).
unbind
(
'error'
).
triggerHandler
(
'error'
);
message
=
"unbind all"
;
$elem
.
bind
(
'error'
,
error
).
unbind
().
triggerHandler
(
'error'
);
message
=
"unbind many with function"
;
$elem
.
bind
(
'error error2'
,
error
)
.
unbind
(
'error error2'
,
error
)
.
trigger
(
'error'
).
triggerHandler
(
'error2'
);
message
=
"unbind many"
;
// #3538
$elem
.
bind
(
'error error2'
,
error
)
.
unbind
(
'error error2'
)
.
trigger
(
'error'
).
triggerHandler
(
'error2'
);
});
test
(
"unbind(eventObject)"
,
function
()
{
expect
(
4
);
var
$elem
=
jQuery
(
"#firstp"
),
num
;
function
assert
(
expected
){
num
=
0
;
$elem
.
trigger
(
'foo'
).
triggerHandler
(
'bar'
);
equals
(
num
,
expected
,
"Check the right handlers are triggered"
);
}
$elem
// This handler shouldn't be unbound
.
bind
(
'foo'
,
function
(){
num
+=
1
;
})
.
bind
(
'foo'
,
function
(
e
){
$elem
.
unbind
(
e
)
num
+=
2
;
})
// Neither this one
.
bind
(
'bar'
,
function
(){
num
+=
4
;
});
assert
(
7
);
assert
(
5
);
$elem
.
unbind
(
'bar'
);
assert
(
1
);
$elem
.
unbind
();
assert
(
0
);
});
test
(
"trigger() shortcuts"
,
function
()
{
test
(
"trigger() shortcuts"
,
function
()
{
expect
(
6
);
expect
(
6
);
jQuery
(
'<li><a href="#">Change location</a></li>'
).
prependTo
(
'#firstUL'
).
find
(
'a'
).
bind
(
'click'
,
function
()
{
jQuery
(
'<li><a href="#">Change location</a></li>'
).
prependTo
(
'#firstUL'
).
find
(
'a'
).
bind
(
'click'
,
function
()
{
...
@@ -232,43 +298,6 @@ test("trigger() bubbling", function() {
...
@@ -232,43 +298,6 @@ test("trigger() bubbling", function() {
equals
(
ap
,
1
,
"ap bubble"
);
equals
(
ap
,
1
,
"ap bubble"
);
});
});
test
(
"unbind(event)"
,
function
()
{
expect
(
8
);
var
el
=
jQuery
(
"#firstp"
);
el
.
click
(
function
()
{
ok
(
true
,
"Fake normal bind"
);
});
el
.
click
(
function
(
event
)
{
el
.
unbind
(
event
);
ok
(
true
,
"Fake onebind"
);
});
el
.
click
().
click
();
el
.
click
(
function
()
{
return
;
});
el
.
unbind
(
'click'
);
ok
(
!
el
[
0
].
onclick
,
"Handler is removed"
);
// Bug #964
el
.
click
(
function
()
{
return
;
});
el
.
unbind
(
'change'
,
function
(){
return
;
});
for
(
var
ret
in
jQuery
.
data
(
el
[
0
],
"events"
)[
'click'
])
break
;
ok
(
ret
,
"Extra handlers weren't accidentally removed."
);
el
.
unbind
(
'click'
);
ok
(
!
jQuery
.
data
(
el
[
0
],
"events"
),
"Removed the events expando after all handlers are unbound."
);
reset
();
var
clickCounter
=
(
mouseoverCounter
=
0
);
var
handler
=
function
(
event
)
{
if
(
event
.
type
==
"click"
)
clickCounter
+=
1
;
else
if
(
event
.
type
==
"mouseover"
)
mouseoverCounter
+=
1
;
};
jQuery
(
"#firstp"
).
bind
(
"click mouseover"
,
handler
).
unbind
(
"click mouseover"
,
handler
).
trigger
(
"click"
).
trigger
(
"mouseover"
);
equals
(
clickCounter
,
0
,
"unbind() with multiple events at once"
);
equals
(
mouseoverCounter
,
0
,
"unbind() with multiple events at once"
);
});
test
(
"trigger(type, [data], [fn])"
,
function
()
{
test
(
"trigger(type, [data], [fn])"
,
function
()
{
expect
(
11
);
expect
(
11
);
...
...
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