dollar-js
Version:
A lighter, faster, modular jQuery replacement (manipulate DOM, bind events, and more...)
1,531 lines (1,111 loc) • 106 kB
JavaScript
!(function(global, window, document){
require([
[(function (require, module, exports) {
/**
* Run your specs
*/
var runInBrowser = require(4);
require.cache.clear();
var FeatherTestSpecMap = { "test_specs_core__utils_each_spec": function(){ require(5); },
"test_specs_core__utils_extend_spec": function(){ require(6); },
"test_specs_core__utils_spec": function(){ require(7); },
"test_specs_core_closest_spec": function(){ require(8); },
"test_specs_core_each_spec": function(){ require(9); },
"test_specs_core_eq_spec": function(){ require(10); },
"test_specs_core_filter_spec": function(){ require(11); },
"test_specs_core_find_spec": function(){ require(12); },
"test_specs_filter_add_spec": function(){ require(13); },
"test_specs_filter_concat_spec": function(){ require(14); },
"test_specs_filter_has_spec": function(){ require(15); },
"test_specs_filter_is_spec": function(){ require(16); },
"test_specs_filter_map_spec": function(){ require(17); },
"test_specs_filter_not_spec": function(){ require(18); },
"test_specs_mutate_after_spec": function(){ require(19); },
"test_specs_mutate_append_spec": function(){ require(20); },
"test_specs_mutate_before_spec": function(){ require(21); },
"test_specs_mutate_clone_spec": function(){ require(22); },
"test_specs_mutate_empty_spec": function(){ require(23); },
"test_specs_mutate_html_spec": function(){ require(24); },
"test_specs_mutate_prepend_spec": function(){ require(25); },
"test_specs_mutate_remove_spec": function(){ require(26); },
"test_specs_readwrite_attr_spec": function(){ require(27); },
"test_specs_readwrite_data_spec": function(){ require(28); },
"test_specs_readwrite_prop_spec": function(){ require(29); },
"test_specs_readwrite_removeAttr_spec": function(){ require(30); },
"test_specs_readwrite_removeData_spec": function(){ require(31); },
"test_specs_readwrite_removeProp_spec": function(){ require(32); },
"test_specs_readwrite_text_spec": function(){ require(33); },
"test_specs_readwrite_val_spec": function(){ require(34); },
"test_specs_style_addClass_spec": function(){ require(35); },
"test_specs_style_css_spec": function(){ require(36); },
"test_specs_style_hasClass_spec": function(){ require(37); },
"test_specs_style_height_spec": function(){ require(38); },
"test_specs_style_hide_spec": function(){ require(39); },
"test_specs_style_removeClass_spec": function(){ require(40); },
"test_specs_style_show_spec": function(){ require(41); },
"test_specs_style_width_spec": function(){ require(42); },
"test_specs_traverse_children_spec": function(){ require(43); },
"test_specs_traverse_first_spec": function(){ require(44); },
"test_specs_traverse_last_spec": function(){ require(45); },
"test_specs_traverse_next_spec": function(){ require(46); },
"test_specs_traverse_parent_spec": function(){ require(47); },
"test_specs_traverse_prev_spec": function(){ require(48); },
"test_specs_traverse_siblings_spec": function(){ require(49); },
"test_specs_trigger_off_spec": function(){ require(50); },
"test_specs_trigger_on_spec": function(){ require(51); },
"test_specs_trigger_trigger_spec": function(){ require(52); },
"test_specs___spec": function(){ require(53); },
};
runInBrowser(FeatherTestSpecMap);
/* cleanup environment */
__dirname = "/";
}),{"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"32":32,"33":33,"34":34,"35":35,"36":36,"37":37,"38":38,"39":39,"40":40,"41":41,"42":42,"43":43,"44":44,"45":45,"46":46,"47":47,"48":48,"49":49,"50":50,"51":51,"52":52,"53":53}],
[(function (require, module, exports) {
function each (collection, iteratee, thisArg) {
if (collection) {
if (typeof collection.length !== 'undefined') {
for (var i = 0, len = collection.length; i < len; i++) {
if (iteratee.call(thisArg, collection[i], i, collection) === false) {
return;
}
}
} else {
for (var i = 0, keys = Object.keys(collection), len = keys.length; i < len; i++) {
if (iteratee.call(thisArg, collection[keys[i]], keys[i], collection) === false) {
return;
}
}
}
}
}
module.exports = each;
}),{}],
[(function (require, module, exports) {
function clear (key) {
return window.localStorage.setItem(key, null);
}
function get (key) {
try {
return JSON.parse(window.localStorage.getItem(key));
} catch (e) {
return null;
}
}
function set (key, value) {
try {
return window.localStorage.setItem(key, JSON.stringify(value));
} catch (e) {
// do nothing
}
}
function mergeResults (key, results) {
var storedResults = get(key) || { failed: [], passed: [], skipped: [] };
if (storedResults) {
storedResults.failed = storedResults.failed.concat(results.failed);
storedResults.passed = storedResults.passed.concat(results.passed);
storedResults.skipped = storedResults.skipped.concat(results.skipped);
}
return set(key, storedResults);
}
module.exports = {
mergeResults: mergeResults,
get: get,
set: set,
clear: clear,
};
}),{}],
[(function (require, module, exports) {
module.exports = '<style>body,html{background:#eee}#again{background-color:#794e79;width:50%;max-width:230px;border-radius:6px;padding:20px 40px;margin:40px auto 30px auto;box-shadow:1px 2px 3px rgba(0,0,0,.5);font-size:24px;color:#fff;text-align:center;font-family:sans-serif;cursor:pointer}#passing{width:100%;max-width:600px;display:block;margin:auto}#results{width:100%;max-width:800px;margin:20px auto 80px auto}#results a{line-height:2em}</style><div id="again">Run tests again</div><img id="passing" src="passing.gif"><pre id="results"></pre>';
}),{}],
[(function (require, module, exports) {
/**
* Run specs in Browser
*/
var each = require(1);
var storage = require(2);
var runningState = 'running';
var finishedState = 'finished';
/* helpers */
function currentBaseUrl() {
return window.location.protocol + '//' + window.location.host + window.location.pathname;
}
function parseKeyvalString(str) {
var delimiter = "&";
var associativeOperator = "=";
var result = {};
var decodedStr = str ? decodeURIComponent(str) : null;
if (decodedStr) {
var keylessCount = 1;
var keyvals = decodedStr.split(delimiter);
each(keyvals, function (kv) {
var keyval = kv.split(associativeOperator);
if (keyval.length >= 2) {
var key = keyval.shift();
var val = keyval.join("=");
if (key) {
result[key.trim()] = val.trim();
}
} else if (keyval[0]) {
result["KEYLESS_VALUE_" + keylessCount] = keyval[0].trim();
keylessCount += 1;
}
});
}
return result;
}
function toQueryString(keyvals) {
var delimiter = "&";
var associativeOperator = "=";
var str = [];
Object.keys(keyvals).forEach(function (k) {
var v = keyvals[k];
str.push(k + associativeOperator + v);
});
return str.join(delimiter);
}
function parseLocationSearch(locationSearch) {
var search = (locationSearch || window.location.search);
return parseKeyvalString(search.slice(1));
}
function runInBrowser(FeatherTestSpecMap) {
function matchSpec(specName) {
for (var key in FeatherTestSpecMap) {
if (key === specName) {
return key;
}
}
return false;
}
function specAfter(specName) {
var keys = Object.keys(FeatherTestSpecMap);
var next;
each(keys, function (k, i) {
if (k === specName) {
next = keys[i + 1];
}
});
return next;
}
function getNextUrlValues(spec, next, running) {
if (!spec && !next) {
/* first run. deafult to running all specs continuously */
var keys = Object.keys(FeatherTestSpecMap);
spec = keys[0];
next = keys[1];
running = true;
return toQueryString({
spec: spec,
next: next,
state: runningState,
});
} else if (!running) {
/* don"t wanna continue. */
return false;
} else if (!next || !FeatherTestSpecMap[next]) {
/* nothing left, bail */
return false;
} else if (next) {
if (specAfter(next)) {
return toQueryString({
spec: next,
next: specAfter(next),
state: runningState,
});
}
return toQueryString({
spec: next,
state: runningState,
});
}
}
function getUrlForNextTest(spec, next, running) {
var nextUrlValues = getNextUrlValues(spec, next, running);
if (nextUrlValues) {
var nextTestUrl = currentBaseUrl() + "?";
return nextTestUrl + nextUrlValues;
}
return false;
}
function invokeSpec(specName) {
if (specName) {
var realSpecName = matchSpec(specName);
if (realSpecName) {
console.log('Running ' + specName);
FeatherTestSpecMap[realSpecName]();
} else {
console.error("Cannot find the spec: " + spec);
}
}
}
function getReporterOutput(results) {
var resultsOutput = '';
/**
* Here we intercept console log, then run the reporter as normal to capture the output
*/
var oldLog = console.log;
console.log = function () {
each(arguments, function (arg) {
resultsOutput += '\n' + arg;
});
oldLog.apply(this, arguments);
};
var oldError = console.error;
console.error = function () {
each(arguments, function (arg) {
resultsOutput += '\n' + arg;
});
oldError.apply(this, arguments);
};
FeatherTest.reporter.report(results);
console.log = oldLog;
console.error = oldError;
return resultsOutput;
}
var options = parseLocationSearch();
var running = options.state === runningState;
var finished = options.state === finishedState;
var spec = matchSpec(options.spec);
var next = matchSpec(options.next);
if (finished) {
var specHyperlinks = [];
var specOutput = storage.get('featherOutput');
if (specOutput) {
console.info('Spec Output:\n', specOutput);
each(specOutput.split('\n'), function (specOut) {
if (specOut && specOut.indexOf('Running ') === 0) {
var specName = specOut.split(' ').pop();
specHyperlinks.push('<a href="?spec=' + specName + '">' + specName + '</a>');
}
});
}
document.body.innerHTML = require(3);
var runAgain = document.getElementById('again');
runAgain.onclick = function () {
window.location.href = currentBaseUrl();
};
var results = storage.get('featherResults');
if (results) {
var resultsOutput = getReporterOutput(results);
if (specHyperlinks.length) {
resultsOutput += '\n\n\n=== Specs ===\n\n' + specHyperlinks.join('\n');
}
var resultsContainer = document.getElementById('results');
resultsContainer.innerHTML = resultsOutput;
if (results.passed.length && !results.failed.length) {
resultsContainer.style.maxWidth = '600px';
}
} else {
}
} else if (running) {
var oldLog = console.log;
console.log = function () {
each(arguments, function (arg) {
var currentOutput = storage.get('featherOutput') || '';
storage.set('featherOutput', currentOutput + '\n' + arg);
});
oldLog.apply(this, arguments);
};
invokeSpec(spec);
FeatherTest.reporter.report = function (results) {
storage.mergeResults('featherResults', results);
var nextUrl = getUrlForNextTest(spec, next, running);
if (nextUrl) {
window.location.href = nextUrl;
} else {
window.location.href = currentBaseUrl() + '?state=' + finishedState;
}
};
FeatherTest.report();
} else {
// cleanup for a fresh run
storage.clear('featherOutput');
storage.clear('featherResults');
if (options.spec) {
if (spec) {
invokeSpec(spec);
FeatherTest.report();
} else {
console.error('Spec "' + options.spec + '" not found within this test bundle');
console.log('Try one of the following:');
each(FeatherTestSpecMap, function (fn, specName) {
console.log(specName);
});
}
} else {
window.location.href = currentBaseUrl() + '?state=' + runningState;
}
}
}
module.exports = runInBrowser;
}),{"1":1,"2":2,"3":3}],
[(function (require, module, exports) {
(function () {
describe("utils.each", function () {
var arr = [1, 2, 3];
var obj = { abc: 123, def: 456 };
describe("when given undefined", function () {
var called = false;
function cb () {
called = true;
}
it("does not call the callback", function (expect) {
$.utils.each(void 0, cb);
expect(called).toBe(false);
});
});
describe("when given an empty array", function () {
var called = false;
function cb () {
called = true;
}
it("does not call the callback", function (expect) {
$.utils.each([], cb);
expect(called).toBe(false);
});
});
describe("when given an array with length", function () {
it("iterates the array", function (expect) {
var actual = [],
expected = [
{ ndx: 0, val: 1, col: arr },
{ ndx: 1, val: 2, col: arr },
{ ndx: 2, val: 3, col: arr }
];
$.utils.each(arr, function(v, k, c) {
actual.push({ ndx: k, val: v, col: c });
});
expect(actual).toEqual(expected);
});
});
describe("when given an NodeList", function () {
it("iterates the NodeList", function (expect) {
var nl = document.querySelectorAll('body'),
actual = [],
expected = [
{ ndx: 0, val: nl[0], col: nl }
];
$.utils.each(nl, function(v, k, c) {
actual.push({ ndx: k, val: v, col: c });
});
expect(actual).toEqual(expected);
});
});
describe("when given an arguments object", function () {
it("iterates the arguments", function (expect) {
var each = $.utils.each;
var actual = [];
var expected;
function someFn () {
expected = [
{ ndx: 0, val: arguments[0], col: arguments },
{ ndx: 1, val: arguments[1], col: arguments }
];
each(arguments, function(v, k, c) {
actual.push({ ndx: k, val: v, col: c });
});
}
someFn('arg1', 'arg2');
expect(actual).toEqual(expected);
});
});
describe("when given an object", function () {
it("iterates the object", function (expect) {
var actual = [],
expected = [
{ key: 'abc', val: 123, col: obj },
{ key: 'def', val: 456, col: obj }
];
$.utils.each(obj, function(v, k, c) {
actual.push({ key: k, val: v, col: c });
});
expect(actual).toEqual(expected);
});
});
describe("when given an object with length (jquery)", function () {
it("iterates the object as it would an array", function (expect) {
var jq = $('body'),
actual = [],
expected = [
{ key: 0, val: jq.get(0), col: jq }
];
$.utils.each(jq, function(v, k, c) {
actual.push({ key: k, val: v, col: c });
});
expect(actual).toEqual(expected);
});
});
describe("when an iteratee returns false", function () {
it("drops out of the loop", function (expect) {
var lastVal;
$.utils.each(arr, function(v) {
lastVal = v;
return false;
});
expect(lastVal).toBe(1);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe("utils.extend", function () {
describe("when given two objects", function () {
it("combines properties from both into one object", function (expect) {
expect($.utils.extend({ bat: 'man' }, { super: 'man' })).toEqual({ bat: 'man', super: 'man' });
});
it("modifies the first object directly", function (expect) {
var obj = { bat: 'man' };
$.utils.extend(obj, { super: 'man' });
$.utils.extend(obj, { sand: 'man' });
expect(obj).toEqual({ bat: 'man', super: 'man', sand: 'man' });
});
it("overwrites the first with the second", function (expect) {
expect($.utils.extend({ bat: 'man' }, { bat: 'girl' })).toEqual({ bat: 'girl' });
});
});
});
})();
}),{}],
[(function (require, module, exports) {
describe("utils", function () {
describe("isElement", function () {
it("handles undefined", function (expect) {
expect($.utils.isElement()).toBe(false);
});
it("returns false for non-elements", function (expect) {
expect($.utils.isElement(window)).toBe(false);
});
it("returns true for elements", function (expect) {
expect($.utils.isElement(document.getElementById('slim_shady'))).toBe(true);
});
});
});
}),{}],
[(function (require, module, exports) {
(function () {
describe(".closest", function () {
var contextSelector = SELECTORS.contextSelector;
describe("handles all types of selectors", function () {
var emptyDollar = $();
it("handles no selector", function (expect) {
expect($(contextSelector).closest()).toEqual(emptyDollar);
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as selector", function (expect) {
expect($(contextSelector).closest(sel)).toEqual(emptyDollar);
});
});
it("handles dollar instance as selector", function (expect) {
expect($(contextSelector).closest($('article')).get()).toEqual($('article').get());
});
it("handles Node as selector", function (expect) {
expect($(contextSelector).closest(document)[0]).toEqual(document);
});
it("handles Element as selector", function (expect) {
var elem = document.getElementById('top_list');
expect($(contextSelector).closest(elem)[0]).toEqual(elem);
});
});
describe("finds closest elements", function () {
jQuery.each(SELECTORS.context, function (sel) {
it("matches '" + sel + "' as selector", function (expect) {
expect($(contextSelector).closest(sel)).toMatchElements('#top_list');
});
});
});
describe("finds within context", function () {
jQuery.each(SELECTORS.context, function (context) {
it("within '" + context + "' as context", function (expect) {
expect($(contextSelector).closest('ul', context)).toMatchElements(jQuery('#top_list ul'));
});
});
});
describe("handles all types of context", function () {
var emptyDollar = $();
jQuery.each(SELECTORS.ignored, function (name, context) {
it("handles " + name + " as context", function (expect) {
expect($(contextSelector).closest(context)).toEqual(emptyDollar);
});
});
it("handles dollar instance as context", function (expect) {
expect($(contextSelector).closest($('article')).get()).toEqual($('article').get());
});
it("handles Node as context", function (expect) {
expect($(contextSelector).closest(document)[0]).toEqual(document);
});
it("handles Element as context", function (expect) {
var elem = document.getElementById('top_list');
expect($(contextSelector).closest(elem)[0]).toEqual(elem);
});
});
describe("is chainable", function () {
it("returns dollar instance", function (expect) {
expect($(contextSelector).closest('foo').isDollar).toBe(true);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".each", function () {
describe("iterates over each element in a dollar instance", function () {
it("executes the correct number of times", function (expect) {
var times = 0;
$('section').each(function () { times++; });
expect(times).toBe(3);
});
it("drops out when return false", function (expect) {
var times = 0;
$('section').each(function () { times++; return false; });
expect(times).toBe(1);
});
it("passes the correct args to iteratee", function (expect) {
var args = [];
$('#slim_shady').each(function (elem, index) {
args.push(this);
args.push(elem);
args.push(index);
});
expect(args).toEqual([
document.getElementById('slim_shady'),
document.getElementById('slim_shady'),
0
]);
});
});
describe("is chainable", function () {
it("returns dollar instance", function (expect) {
expect($('.wonka').each(function () {}).isDollar).toBe(true);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".eq", function () {
describe("handles all types of selectors", function () {
var emptyDollar = $();
var elem = document.getElementById('slim_shady');
it("handles no selector", function (expect) {
expect($('section').eq()).toEqual(emptyDollar);
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as selector", function (expect) {
expect($('section').eq(sel)).toEqual(emptyDollar);
});
});
it("handles dollar instance as selector", function (expect) {
expect($('section').eq($('a'))).toEqual(emptyDollar);
});
it("handles Element as selector", function (expect) {
expect($('section').eq(elem)).toEqual(emptyDollar);
});
it("handles function as selector", function (expect) {
expect($('section').eq(function () {})).toEqual(emptyDollar);
});
});
describe("returns the matched element at a given index", function () {
it("gets a zero index", function (expect) {
expect($('section').eq(0)).toMatchElements('#first_section');
expect($('section').eq('0')).toMatchElements('#first_section');
});
it("gets a positive index", function (expect) {
expect($('section').eq(1)).toMatchElements('#middle_section');
expect($('section').eq('1')).toMatchElements('#middle_section');
});
it("gets a negative index", function (expect) {
expect($('section').eq(-1)).toMatchElements('#last_section');
expect($('section').eq('-1')).toMatchElements('#last_section');
});
});
describe("is chainable", function () {
it("returns dollar instance", function (expect) {
expect($('section').eq(0).isDollar).toBe(true);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".filter", function () {
describe("handles all types of selectors", function () {
var emptyDollar = $();
it("handles no selector", function (expect) {
expect($('*').filter()).toEqual(emptyDollar);
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as selector", function (expect) {
expect($('*').filter(sel)).toEqual(emptyDollar);
});
});
it("handles dollar instance as selector", function (expect) {
expect($('*').filter($('a')).get()).toEqual($('a').get());
});
it("handles Element as selector", function (expect) {
var elem = document.getElementById('slim_shady');
expect($('*').filter(elem)[0]).toEqual(elem);
});
it("handles function as selector", function (expect) {
var elem = document.getElementById('slim_shady');
expect($('*').filter(function (elem, i) {
return elem.id === 'slim_shady';
})).toMatchElements('#slim_shady');
});
});
describe("avoids accidental matches", function () {
jQuery.each(SELECTORS.nomatch, function (i, sel) {
it("does not match '" + sel + "'", function (expect) {
expect($('*').filter(sel).length).toBe(0);
});
});
});
describe("matches our DOM", function () {
jQuery.each(SELECTORS.matchJQuery, function (sel, match) {
it("matches '" + sel + "'", function (expect) {
expect($('*').filter(sel)).toMatchElements(match);
});
});
});
describe("is chainable", function () {
it("returns dollar instance", function (expect) {
expect($('*').filter('foo').isDollar).toBe(true);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".find", function () {
var $b = $(document.getElementsByTagName('body')[0]);
describe("handles all types of selectors", function () {
var emptyDollar = $();
it("handles no selector", function (expect) {
expect($b.find()).toEqual(emptyDollar);
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as selector", function (expect) {
expect($b.find(sel)).toEqual(emptyDollar);
});
});
it("handles dollar instance as selector", function (expect) {
expect($b.find($('a')).get()).toEqual($('a').get());
});
describe('finding within parent found with string selector', function () {
it('searches within a string parent for string child', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $(parent).find(children);
var jQueryFound = jQuery(parent).find(children);
expect($found).toMatchElements(jQueryFound);
});
it('searches within a string parent for $children', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $(parent).find($(children));
var jQueryFound = jQuery(parent).find(jQuery(children));
expect($found).toMatchElements(jQueryFound);
});
it('searches within a string parent for single node child', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $(parent).find(document.getElementsByClassName(children)[0]);
var jQueryFound = jQuery(parent).find(document.getElementsByClassName(children)[0]);
expect($found).toMatchElements(jQueryFound);
});
it('searches within a string parent for many node children', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $(parent).find(document.getElementsByClassName(children));
var jQueryFound = jQuery(parent).find(document.getElementsByClassName(children));
expect($found).toMatchElements(jQueryFound);
});
});
describe('finding within a parent found with $', function () {
it('searches within a $parent for string children', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $($(parent)).find(children);
var jQueryFound = jQuery(jQuery(parent)).find(children);
expect($found).toMatchElements(jQueryFound);
});
it('searches within a $parent for $children', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $($(parent)).find($(children));
var jQueryFound = jQuery(jQuery(parent)).find(jQuery(children));
expect($found).toMatchElements(jQueryFound);
});
it('searches within a $parent for single node child', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $($(parent)).find(document.getElementsByClassName(children)[0]);
var jQueryFound = jQuery(jQuery(parent)).find(document.getElementsByClassName(children)[0]);
expect($found).toMatchElements(jQueryFound);
});
it('searches within a $parent for multiple node children', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $($(parent)).find(document.getElementsByClassName(children));
var jQueryFound = jQuery(jQuery(parent)).find(document.getElementsByClassName(children));
expect($found).toMatchElements(jQueryFound);
});
});
describe('finding within a single parent node', function () {
it('searches within a single node parent for string children', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $(document.getElementById(parent)).find(children);
var jQueryFound = jQuery(document.getElementById(parent)).find(children);
expect($found).toMatchElements(jQueryFound);
});
it('searches within a single node parent for $children', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $(document.getElementById(parent)).find($(children));
var jQueryFound = jQuery(document.getElementById(parent)).find(jQuery(children));
expect($found).toMatchElements(jQueryFound);
});
it('searches within a single node parent for single node child', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $(document.getElementById(parent)).find(document.getElementsByClassName(children)[0]);
var jQueryFound = jQuery(document.getElementById(parent)).find(document.getElementsByClassName(children)[0]);
expect($found).toMatchElements(jQueryFound);
});
it('searches within a single node parent for multiple node children', function (expect) {
var parent = '#first_section';
var children = '.find_me';
var $found = $(document.getElementById(parent)).find(document.getElementsByClassName(children));
var jQueryFound = jQuery(document.getElementById(parent)).find(document.getElementsByClassName(children));
expect($found).toMatchElements(jQueryFound);
});
});
describe('finding within multiple node parents', function () {
it('searches within multiple node parents for string children', function (expect) {
var parent = 'section';
var children = '.find_me';
var $found = $(document.getElementsByTagName(parent)).find(children);
var jQueryFound = jQuery(document.getElementsByTagName(parent)).find(children);
expect($found).toMatchElements(jQueryFound);
});
it('searches within multiple node parents for $children', function (expect) {
var parent = 'section';
var children = '.find_me';
var $found = $(document.getElementsByTagName(parent)).find($(children));
var jQueryFound = jQuery(document.getElementsByTagName(parent)).find(jQuery(children));
expect($found).toMatchElements(jQueryFound);
});
it('searches within multiple node parents for a single node child', function (expect) {
var parent = 'section';
var children = '.find_me';
var $found = $(document.getElementsByTagName(parent)).find(document.getElementsByClassName(children)[0]);
var jQueryFound = jQuery(document.getElementsByTagName(parent)).find(document.getElementsByClassName(children)[0]);
expect($found).toMatchElements(jQueryFound);
});
it('searches within multiple node parents for multiple node children', function (expect) {
var parent = 'section';
var children = '.find_me';
var $found = $(document.getElementsByTagName(parent)).find(document.getElementsByClassName(children));
var jQueryFound = jQuery(document.getElementsByTagName(parent)).find(document.getElementsByClassName(children));
expect($found).toMatchElements(jQueryFound);
});
});
});
describe("only finds children", function () {
it("matches children", function (expect) {
expect($('#top_list').find(SELECTORS.contextSelector)).toMatchElements('.sel-in-context-id');
});
});
describe("avoids accidental matches", function () {
jQuery.each(SELECTORS.nomatch, function (i, sel) {
it("does not match '" + sel + "'", function (expect) {
expect($b.find(sel).length).toBe(0);
});
});
});
describe("matches our DOM", function () {
jQuery.each(SELECTORS.matchJQuery, function (sel, match) {
it("matches '" + sel + "'", function (expect) {
expect($b.find(sel)).toMatchElements(match);
});
});
});
describe("is chainable", function () {
it("returns dollar instance", function (expect) {
expect($b.find('foo').isDollar).toBe(true);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".add", function () {
it("merges results into current set", function (expect) {
expect($('#first_section').add('#middle_section').add('#last_section')).toMatchElements('section');
});
it("is chainable", function (expect) {
expect($('#first_section').add('foo').isDollar).toBe(true);
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".concat", function () {
it("merges results into current set", function (expect) {
var e1 = document.getElementById('middle_section');
var e2 = document.getElementById('last_section');
expect($('#first_section').concat([e1, e2], [e2])).toMatchElements('section');
});
it("is chainable", function (expect) {
expect($('#first_section').concat([]).isDollar).toBe(true);
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".has", function () {
var emptyDollar = $();
var $b = $('body');
describe("handles all types of selectors", function () {
it("handles no selector", function (expect) {
expect($b.has()).toEqual(emptyDollar);
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as selector", function (expect) {
expect($b.has(sel)).toEqual(emptyDollar);
});
});
it("handles Element as selector", function (expect) {
var elem = document.getElementById('slim_shady');
expect($b.has(elem).get()).toEqual($b.get());
});
it("handles function as selector", function (expect) {
expect($b.has(function () {})).toEqual(emptyDollar);
});
});
describe("avoids accidental matches", function () {
it("body does not have '#bad'", function (expect) {
expect($b.has('#bad')).toEqual(emptyDollar);
});
});
describe("matches valid selectors", function () {
jQuery.each(SELECTORS.matchJQuery, function (sel, match) {
it("body has " + sel, function (expect) {
expect($b.has(sel).get()).toEqual($b.get());
});
});
});
describe("is chainable", function () {
it("returns dollar instance", function (expect) {
expect($b.has('foo').isDollar).toBe(true);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".is", function () {
describe("handles all types of selectors", function () {
it("handles no selector", function (expect) {
expect($('#slim_shady').is()).toBe(false);
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as selector", function (expect) {
expect($('#slim_shady').is(sel)).toBe(false);
});
});
it("handles dollar instance as selector", function (expect) {
expect($('#slim_shady').is($('div'))).toBe(true);
});
it("handles Element as selector", function (expect) {
var elem = document.getElementById('slim_shady');
expect($('#slim_shady').is(elem)).toBe(true);
});
it("handles function as selector", function (expect) {
var elem = document.getElementById('slim_shady');
expect($('#slim_shady').is(function () {
return this === elem;
})).toBe(true);
});
});
describe("avoids accidental matches", function () {
it("div is not body", function (expect) {
expect($('#slim_shady').is('body')).toBe(false);
});
});
describe("matches valid selectors", function () {
jQuery.each(SELECTORS.matchJQuery, function (sel, match) {
it("at least one " + match + " is " + sel, function (expect) {
expect($(match).is(sel)).toBe(true);
});
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".map", function () {
it("repopulates current set", function (expect) {
var newSet = $('p span').map(function (el) {
return el.parentNode;
});
expect(newSet.get()).toEqual(jQuery('#first_paragraph').add('span.sel-child').get());
});
it("is chainable", function (expect) {
expect($('#first_section').map(function(el){ return el; }).isDollar).toBe(true);
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".not", function () {
var contextSelector = SELECTORS.contextSelector;
describe("handles all types of selectors", function () {
var elem = document.getElementById('top_list');
it("handles no selector", function (expect) {
expect($(contextSelector).not()).toMatchElements($(contextSelector));
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as selector", function (expect) {
expect($(contextSelector).not(sel)).toMatchElements($(contextSelector));
});
});
it("handles dollar instance as selector", function (expect) {
expect($(contextSelector).not($('.top-list'))).toMatchElements(jQuery(contextSelector).not(jQuery('.top-list')));
});
it("handles Element as selector", function (expect) {
expect($(contextSelector).not(elem)).toMatchElements(jQuery(contextSelector).not(elem));
});
it("handles Array of Elements as selector", function (expect) {
expect($(contextSelector).not([elem, elem, elem])).toMatchElements(jQuery(contextSelector).not([elem, elem, elem]));
});
it("handles function as selector", function (expect) {
var fnTest = function () { return this.id === 'top_list'; };
expect($(contextSelector).not(fnTest)).toMatchElements(jQuery(contextSelector).not(fnTest));
});
});
describe("avoids accidental drops", function () {
it("should keep all elements if nothing is matched", function (expect) {
expect($(contextSelector).get()).toEqual($(contextSelector).not('#bad').get());
});
});
describe("drops valid matches", function () {
var emptyDollar = $();
jQuery.each(SELECTORS.matchJQuery, function (sel, match) {
it("drops " + sel, function (expect) {
expect($(match).not(sel)).toEqual(emptyDollar);
});
});
});
describe("is chainable", function () {
it("returns dollar instance", function (expect) {
expect($(contextSelector).not('foo').isDollar).toBe(true);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".after", function () {
describe("handles all types of contents", function () {
it("handles no content", function (expect) {
$('.mutate').after();
expect(jQuery('div', '#mutate').length).toBe(3);
expect(jQuery('span', '#mutate').length).toBe(3);
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as content", function (expect) {
$('.mutate').after(sel);
expect(jQuery('div', '#mutate').length).toBe(3);
expect(jQuery('span', '#mutate').length).toBe(3);
});
});
it("handles Element as content", function (expect) {
var elem = document.createElement('div');
elem.className = 'newAfter';
$('#mutate').after(elem);
expect(jQuery('.newAfter').get()).toEqual([elem]);
});
it("handles dollar instance as content", function (expect) {
$('#mutate').after($('<div class="newAfter">'));
expect(jQuery('.newAfter').length).toBe(1);
});
it("handles function as content", function (expect) {
$('.mutate').after(function () {
return '<div class="newAfter"></div>';
});
expect(jQuery('.newAfter').length).toBe(3);
});
it("handles Array as content", function (expect) {
var elem = document.createElement('div');
elem.className = 'newAfter';
var creator = function () {
return '<div class="newAfter"></div>';
};
$('#mutate').after([elem, creator]);
expect(jQuery('.newAfter').length).toEqual(2);
});
});
describe("inserts new content after", function () {
it("adds content after each", function (expect) {
$('section').after('<div class="newAfter">');
expect(jQuery('section').next()).toMatchElements('.newAfter');
});
it("takes multiple args", function (expect) {
$('section').after('<div class="newAfter">', '<a class="newAfter">', '<span class="newAfter">');
expect(jQuery('.newAfter').length).toBe(9);
});
});
describe("is chainable", function () {
it("returns dollar instance", function (expect) {
expect($('.wonka').after('foo').isDollar).toBe(true);
});
});
});
})();
}),{}],
[(function (require, module, exports) {
(function () {
describe(".append", function () {
describe("handles all types of contents", function () {
it("handles no content", function (expect) {
$('.mutate').append();
expect(jQuery('div', '#mutate').length).toBe(3);
expect(jQuery('span', '#mutate').length).toBe(3);
});
jQuery.each(SELECTORS.ignored, function (name, sel) {
it("handles " + name + " as content", function (expect) {
$('.mutate').append(sel);
expect(jQuery('div', '#mutate').length).toBe(3);
expect(jQuery('span', '#mutate').length).toBe(3);
});
});
it("handles HTMLString (single tag) as content", function (expect) {
expect(jQuery('h1', '#mutate').length).toBe(0);
$('#mutate').append('<h1></h1>');
expect(jQuery('h1', '#mutate').length).toBe(1);
});
it("handles HTMLString (multi tag) as content", function (expect) {
expect(jQuery('h1', '#mutate').length).toBe(0);
$('#mutate').append('<div><h1></h1></div>');
expect(jQuery('div h1', '#mutate').length).toBe(1);
});
it("handles Element as content", function (expect) {
var elem = document.createElement('div');
elem.className = 'newAppend';
$('#mutate').append(elem);
expect(jQuery('.newAppend').get()).toEqual([elem]);
});
it("han