-
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.
Updated some tests to use module format. Added more tests to getVal(). Added tests for $.fn.closest() and $.fn.parentsUntil(). Fixed bugs in $.fn.parentsUntil() where it returned the matching element, and didn't filter the nodes correctly.
- Loading branch information
Showing
17 changed files
with
380 additions
and
221 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.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Large diffs are not rendered by default.
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
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,46 +1,53 @@ | ||
import $ from "../../../dist/dabby.js"; | ||
|
||
QUnit.module("Attributes"); | ||
|
||
QUnit.test("$.fn.attr", function (assert) { | ||
QUnit.module("Attributes", hooks => { | ||
var test = document.getElementsByClassName("test")[0]; | ||
test.innerHTML = '<div class="testtemp"></div>'; | ||
var main = $(".testtemp"), | ||
rmain = document.getElementsByClassName("testtemp")[0], | ||
style = "padding-top: 10px;", | ||
correct = true; | ||
|
||
// set and get class | ||
assert.deepEqual(main.attr("class", "testtemp testclass"), main, "Returns itself when setting class"); | ||
assert.equal(rmain.className, "testtemp testclass", "Can set class"); | ||
assert.equal(main.attr("class"), "testtemp testclass", "Can retrieve class"); | ||
main.attr("class", "testtemp"); | ||
assert.equal(main.attr("class"), "testtemp", "Can remove class"); | ||
|
||
// set and get style | ||
assert.deepEqual(main.attr("style", style), main, "Returns itself when setting style"); | ||
assert.equal(rmain.style.cssText, style, "Can set style"); | ||
assert.equal(main.attr("style"), style, "Can retrieve style"); | ||
|
||
// set and get attribute | ||
assert.deepEqual(main.attr("itemprop", "articleBody"), main, "Returns itself when setting property"); | ||
assert.equal(rmain.getAttribute("itemprop"), "articleBody", "Can set property"); | ||
assert.equal(main.attr("itemprop"), "articleBody", "Can retrieve property"); | ||
main.attr("itemprop", null); | ||
assert.equal(main.attr("itemprop"), undefined, "Can remove property"); | ||
|
||
// set attributes using a callback | ||
test.innerHTML = '<div class="testtemp"></div><div class="testtemp"></div><div class="testtemp"></div>'; | ||
main = $(".testtemp"); | ||
assert.deepEqual(main.attr("data-test", function (i, el) {return "test-"+i;}), main, "Returns itself when setting attribute using callback"); | ||
main.each(function (i) { | ||
if (this.getAttribute("data-test") !== "test-"+i) { | ||
correct = false; | ||
return false; | ||
} | ||
|
||
hooks.before(() => { | ||
test.innerHTML = '<div class="testtemp"></div>'; | ||
}); | ||
|
||
QUnit.test("$.fn.attr", function (assert) { | ||
var main = $(".testtemp"), | ||
rmain = document.getElementsByClassName("testtemp")[0], | ||
style = "padding-top: 10px;", | ||
correct = true; | ||
|
||
// set and get class | ||
assert.deepEqual(main.attr("class", "testtemp testclass"), main, "Returns itself when setting class"); | ||
assert.equal(rmain.className, "testtemp testclass", "Can set class"); | ||
assert.equal(main.attr("class"), "testtemp testclass", "Can retrieve class"); | ||
main.attr("class", "testtemp"); | ||
assert.equal(main.attr("class"), "testtemp", "Can remove class"); | ||
|
||
// set and get style | ||
assert.deepEqual(main.attr("style", style), main, "Returns itself when setting style"); | ||
assert.equal(rmain.style.cssText, style, "Can set style"); | ||
assert.equal(main.attr("style"), style, "Can retrieve style"); | ||
|
||
// set and get attribute | ||
assert.deepEqual(main.attr("itemprop", "articleBody"), main, "Returns itself when setting property"); | ||
assert.equal(rmain.getAttribute("itemprop"), "articleBody", "Can set property"); | ||
assert.equal(main.attr("itemprop"), "articleBody", "Can retrieve property"); | ||
main.attr("itemprop", null); | ||
assert.equal(main.attr("itemprop"), undefined, "Can remove property"); | ||
|
||
// set attributes using a callback | ||
test.innerHTML = '<div class="testtemp"></div><div class="testtemp"></div><div class="testtemp"></div>'; | ||
main = $(".testtemp"); | ||
assert.deepEqual(main.attr("data-test", function (i, el) {return "test-"+i;}), main, "Returns itself when setting attribute using callback"); | ||
main.each(function (i) { | ||
if (this.getAttribute("data-test") !== "test-"+i) { | ||
correct = false; | ||
return false; | ||
} | ||
}); | ||
assert.equal(correct, true, "Can set property with callback"); | ||
|
||
// reset | ||
}); | ||
assert.equal(correct, true, "Can set property with callback"); | ||
|
||
// reset | ||
test.innerHTML = ""; | ||
hooks.after(() => { | ||
test.innerHTML = ""; | ||
}); | ||
}); |
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,47 +1,48 @@ | ||
import $ from "../../../dist/dabby.js"; | ||
|
||
QUnit.module("Attributes"); | ||
QUnit.module("Attributes", hooks => { | ||
|
||
QUnit.test("$.fn.show", function (assert) { | ||
var test = document.getElementsByClassName("test")[0], | ||
obj; | ||
test.innerHTML = '<div class="testtemp"><div style="display: none;"></div><div style="display: none;"></div><div style="display: none;"><div style="display: none;"></div></div><div style="display: none;"><div style="display: none;"></div></div></div>'; | ||
obj = $(".testtemp div"); | ||
QUnit.test("$.fn.show", function (assert) { | ||
var test = document.getElementsByClassName("test")[0], | ||
obj; | ||
test.innerHTML = '<div class="testtemp"><div style="display: none;"></div><div style="display: none;"></div><div style="display: none;"><div style="display: none;"></div></div><div style="display: none;"><div style="display: none;"></div></div></div>'; | ||
obj = $(".testtemp div"); | ||
|
||
assert.deepEqual(obj.show(), obj, "Returns self on set"); | ||
let show = 0; | ||
obj.get().forEach(item => { | ||
show += item.style.display !== "none"; | ||
assert.deepEqual(obj.show(), obj, "Returns self on set"); | ||
let show = 0; | ||
obj.get().forEach(item => { | ||
show += item.style.display !== "none"; | ||
}); | ||
assert.equal(obj.length, show, "Showed the requested elements"); | ||
}); | ||
assert.equal(obj.length, show, "Showed the requested elements"); | ||
}); | ||
|
||
QUnit.test("$.fn.hide", function (assert) { | ||
var test = document.getElementsByClassName("test")[0], | ||
obj; | ||
test.innerHTML = '<div class="testtemp"><div></div><div></div><div><div></div></div><div><div></div></div></div>'; | ||
obj = $(".testtemp div"); | ||
QUnit.test("$.fn.hide", function (assert) { | ||
var test = document.getElementsByClassName("test")[0], | ||
obj; | ||
test.innerHTML = '<div class="testtemp"><div></div><div></div><div><div></div></div><div><div></div></div></div>'; | ||
obj = $(".testtemp div"); | ||
|
||
assert.deepEqual(obj.hide(), obj, "Returns self on set"); | ||
let hide = 0; | ||
obj.get().forEach(item => { | ||
hide += item.style.display === "none"; | ||
assert.deepEqual(obj.hide(), obj, "Returns self on set"); | ||
let hide = 0; | ||
obj.get().forEach(item => { | ||
hide += item.style.display === "none"; | ||
}); | ||
assert.equal(obj.length, hide, "Hid the requested elements"); | ||
}); | ||
assert.equal(obj.length, hide, "Hid the requested elements"); | ||
}); | ||
|
||
QUnit.test("$.fn.toggle", function (assert) { | ||
var test = document.getElementsByClassName("test")[0], | ||
obj; | ||
test.innerHTML = '<div class="testtemp"><div style="display: none;"></div><div style="display: inline-block;"></div><div style="display: flex;"><div></div></div><div style="display: none;"><div style="display: none;"></div></div></div>'; | ||
obj = $(".testtemp div"); | ||
QUnit.test("$.fn.toggle", function (assert) { | ||
var test = document.getElementsByClassName("test")[0], | ||
obj; | ||
test.innerHTML = '<div class="testtemp"><div style="display: none;"></div><div style="display: inline-block;"></div><div style="display: flex;"><div></div></div><div style="display: none;"><div style="display: none;"></div></div></div>'; | ||
obj = $(".testtemp div"); | ||
|
||
assert.deepEqual(obj.toggle(), obj, "Returns self on set"); | ||
let show = 0, hide = 0; | ||
obj.get().forEach(item => { | ||
hide += item.style.display === "none"; | ||
show += item.style.display !== "none"; | ||
assert.deepEqual(obj.toggle(), obj, "Returns self on set"); | ||
let show = 0, hide = 0; | ||
obj.get().forEach(item => { | ||
hide += item.style.display === "none"; | ||
show += item.style.display !== "none"; | ||
}); | ||
assert.equal(3, show, "Showed the requested elements"); | ||
assert.equal(3, hide, "Hid the requested elements"); | ||
}); | ||
assert.equal(3, show, "Showed the requested elements"); | ||
assert.equal(3, hide, "Hid the requested elements"); | ||
}); |
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,11 +1,30 @@ | ||
import $ from "../../../dist/dabby.js"; | ||
|
||
import getVal from "./getval.js"; | ||
|
||
QUnit.module("Internal"); | ||
QUnit.module("Internal", hooks => { | ||
const test = document.getElementsByClassName("test")[0]; | ||
|
||
hooks.before(() => { | ||
test.innerHTML = '<div class="testtemp"></div><div class="testtemp2"></div><div class="testtemp3"></div>'; | ||
}); | ||
|
||
QUnit.test("getVal", assert => { | ||
const obj = $(".test div"); | ||
assert.deepEqual(getVal(obj, "test"), ["test", "test", "test"], "Can pass-through a value"); | ||
assert.deepEqual(getVal(obj, function () {return $(this).attr("class");}), ["testtemp", "testtemp2", "testtemp3"], "Can use function as value"); | ||
assert.deepEqual(getVal(obj, function (i, current) {return current;}, obj => obj.className), ["testtemp", "testtemp2", "testtemp3"], "Can use function as value and return original value"); | ||
|
||
let clone = {foo: "bar", bar: "foo"}; | ||
const val = getVal(obj, clone); | ||
val.map((item, i) => { | ||
item.foo = "foo" + i; | ||
return item; | ||
}); | ||
assert.deepEqual(val, [{foo: "foo0", bar: "foo"}, {foo: "foo1", bar: "foo"}, {foo: "foo2", bar: "foo"}], "Objects are cloned onto each output"); | ||
assert.deepEqual(clone, {foo: "bar", bar: "foo"}, "Original object was not changed when object was copied to each val"); | ||
}); | ||
|
||
QUnit.test("getVal", function (assert) { | ||
var obj = $(".test"); | ||
assert.deepEqual(getVal(obj, "test"), ["test"], "Can pass-through a value"); | ||
assert.deepEqual(getVal(obj, function (i) {return this === obj[0] && !i ? "test" : false;}), ["test"], "When passing function as value, variables and context is correct"); | ||
hooks.after(() => { | ||
test.innerHTML = ""; | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import $ from "../../../dist/dabby.js"; | ||
|
||
QUnit.module("Traversal", hooks => { | ||
var test = document.getElementsByClassName("test")[0]; | ||
|
||
hooks.before(() => { | ||
test.innerHTML = '<div class="testtemp"><div class="testtemp2"><div class="testtemp3">test</div></div></div>'; | ||
}); | ||
|
||
QUnit.test("$.fn.closest", function (assert) { | ||
const obj = $(".testtemp3, .testtemp2, .testtemp"); | ||
assert.deepEqual(obj.closest(".test").get(), [test, test, test], "Can select parents until a particular node"); | ||
}); | ||
|
||
hooks.after(() => { | ||
test.innerHTML = ""; | ||
}); | ||
}); |
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
Oops, something went wrong.