-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95b6320
commit 8a8e89d
Showing
7 changed files
with
73 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,76 @@ | ||
/*globals afterEach: true, describe: true, it: true, expect: true, beforeEach: true, appendToDom:true, destroyDom:true, $:true*/ | ||
/*globals afterEach: true, describe: true, it: true, expect: true, beforeEach: true, appendToDom:true, destroyDom:true, $$:true*/ | ||
'use strict'; | ||
|
||
describe('api', function () { | ||
describe('no selector', function () { | ||
it('should return on method', function () { | ||
assert(typeof $.on === 'function'); | ||
assert(typeof $$.on === 'function'); | ||
}); | ||
|
||
it('should return trigger method', function () { | ||
assert(typeof $.trigger === 'function'); | ||
assert(typeof $$.trigger === 'function'); | ||
}); | ||
}); | ||
|
||
describe('empty selector', function () { | ||
var $empty = $(''); | ||
var $$empty = $$(''); | ||
|
||
it('should return on method', function () { | ||
assert(typeof $empty.on === 'function'); | ||
assert(typeof $$empty.on === 'function'); | ||
}); | ||
|
||
it('should return trigger method', function () { | ||
assert(typeof $empty.trigger === 'function'); | ||
assert(typeof $$empty.trigger === 'function'); | ||
}); | ||
}); | ||
|
||
describe('iterator', function () { | ||
var $link; | ||
var $$link; | ||
|
||
beforeEach(function () { | ||
appendToDom('section', ['a', 'a', 'a']); | ||
|
||
$link = $('section > a'); | ||
$$link = $$('section > a'); | ||
}); | ||
|
||
afterEach(destroyDom); | ||
|
||
it('should have forEach', function () { | ||
assert(typeof $link.forEach === 'function'); | ||
assert(typeof $$link.forEach === 'function'); | ||
}); | ||
|
||
it('should loop', function () { | ||
var ctr = 0; | ||
$link.forEach(function () { | ||
$$link.forEach(function () { | ||
ctr++; | ||
}); | ||
assert(ctr === 3); | ||
}); | ||
|
||
it('should have each element passed to iterator', function () { | ||
$link.forEach(function (el, i) { | ||
assert(el === $link[i]); | ||
$$link.forEach(function (el, i) { | ||
assert(el === $$link[i]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('matched selector', function () { | ||
var $link; | ||
var $$link; | ||
|
||
beforeEach(function () { | ||
appendToDom('section', ['a']); | ||
|
||
$link = $('section > a'); | ||
$$link = $$('section > a'); | ||
}); | ||
|
||
afterEach(destroyDom); | ||
|
||
it('should return on method', function () { | ||
assert(typeof $link.on === 'function'); | ||
assert(typeof $$link.on === 'function'); | ||
}); | ||
|
||
it('should return trigger method', function () { | ||
assert(typeof $link.trigger === 'function'); | ||
assert(typeof $$link.trigger === 'function'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
/*globals noop:true, appendToDom:true, destroyDom:true, $:true*/ | ||
/*globals noop:true, appendToDom:true, destroyDom:true, $$:true*/ | ||
'use strict'; | ||
|
||
describe('chaining', function () { | ||
describe('no selector', function () { | ||
it('should return trigger method from on', function () { | ||
assert(typeof $.on('event', noop).trigger === 'function'); | ||
assert(typeof $$.on('event', noop).trigger === 'function'); | ||
}); | ||
|
||
it('should return on method from trigger', function () { | ||
assert(typeof $.on('event', noop).trigger('event').on === 'function'); | ||
assert(typeof $$.on('event', noop).trigger('event').on === 'function'); | ||
}); | ||
}); | ||
|
||
// left in, note that Firefox does not support empty selectors | ||
describe('unmatched selector', function () { | ||
it('should return trigger method from on', function () { | ||
assert(typeof $('unmatched').on('event', noop).trigger === 'function'); | ||
assert(typeof $$('unmatched').on('event', noop).trigger === 'function'); | ||
}); | ||
|
||
it('should return on method from trigger', function () { | ||
assert(typeof $('unmatched').on('event', noop).trigger('event').on === 'function'); | ||
assert(typeof $$('unmatched').on('event', noop).trigger('event').on === 'function'); | ||
}); | ||
}); | ||
|
||
describe('empty selector', function () { | ||
it('should still allow for chained methods', function () { | ||
assert(typeof $('').on('event', noop).trigger === 'function'); | ||
assert(typeof $$('').on('event', noop).trigger === 'function'); | ||
}); | ||
}); | ||
|
||
describe('matched selector', function () { | ||
var $link; | ||
var $$link; | ||
|
||
beforeEach(function () { | ||
appendToDom('section', ['a']); | ||
|
||
$link = $('section > a'); | ||
$$link = $$('section > a'); | ||
}); | ||
|
||
afterEach(destroyDom); | ||
|
||
it('should return trigger method from on', function () { | ||
assert(typeof $link.on('event', noop).trigger === 'function'); | ||
assert(typeof $$link.on('event', noop).trigger === 'function'); | ||
}); | ||
|
||
it('should return on method from trigger', function () { | ||
assert(typeof $link.on('event', noop).trigger('event').on === 'function'); | ||
assert(typeof $$link.on('event', noop).trigger('event').on === 'function'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
/*globals appendToDom:true, destroyDom:true, $:true*/ | ||
/*globals appendToDom:true, destroyDom:true, $$:true*/ | ||
'use strict'; | ||
|
||
describe('delegation', function () { | ||
var $section, | ||
$article, | ||
var $$section, | ||
$$article, | ||
spy; | ||
|
||
beforeEach(function () { | ||
spy = sinon.spy(); | ||
appendToDom('section', ['article', 'a', 'a']); | ||
|
||
$section = $('section'); | ||
$article = $('section > article'); | ||
$$section = $$('section'); | ||
$$article = $$('section > article'); | ||
}); | ||
|
||
afterEach(destroyDom); | ||
|
||
it('should trigger container events from children', function () { | ||
var target; | ||
|
||
$section | ||
$$section | ||
.on('event', spy) | ||
.on('event', function (event) { | ||
target = event.target; | ||
}); | ||
|
||
$article.trigger('event'); | ||
$$article.trigger('event'); | ||
|
||
assert(spy.called); | ||
assert(target === $article); | ||
assert(target === $$article); | ||
}); | ||
|
||
it('should trigger click event using event delegation', function () { | ||
$('body').delegate('section > a', 'click', spy); | ||
$('section > a')[0].trigger('click'); | ||
$$('body').delegate('section > a', 'click', spy); | ||
$$('section > a')[0].trigger('click'); | ||
|
||
assert(spy.called); | ||
$('section > a')[0].trigger('click'); | ||
$$('section > a')[0].trigger('click'); | ||
assert(spy.calledTwice); | ||
|
||
$('section > a')[1].trigger('click'); | ||
$$('section > a')[1].trigger('click'); | ||
assert(spy.calledThrice); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters