summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 15:40:04 +0300
committerVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 15:40:04 +0300
commite85128e0887e006ea7dfa28680982649cecbab83 (patch)
treefdc84ffbdefa85566d4ea23f71effc7d9cf0541b
parent20172433c29f9c1edaf0c2717e89e666187542ae (diff)
downloadawesomplete-e85128e0887e006ea7dfa28680982649cecbab83.zip
awesomplete-e85128e0887e006ea7dfa28680982649cecbab83.tar.gz
awesomplete-e85128e0887e006ea7dfa28680982649cecbab83.tar.bz2
Awesomplete.$$ tests
-rw-r--r--test/helpers/doubleDollarSpec.js49
-rw-r--r--test/specHelper.js4
2 files changed, 53 insertions, 0 deletions
diff --git a/test/helpers/doubleDollarSpec.js b/test/helpers/doubleDollarSpec.js
new file mode 100644
index 0000000..c76a10d
--- /dev/null
+++ b/test/helpers/doubleDollarSpec.js
@@ -0,0 +1,49 @@
+describe("Awesomplete.$$", function () {
+
+ $.fixture("options");
+
+ subject(function () { return Awesomplete.$$(this.expression, this.context) });
+
+ describe("with default context", itFindsAllElements);
+
+ describe("with custom context", function () {
+ def("context", function () { return fixture.el });
+
+ itFindsAllElements();
+ });
+
+ // Shared behaviors
+
+ function itFindsAllElements() {
+ it("returns an array of DOM elements", function () {
+ this.expression = "#no-options";
+ expect(this.subject).toEqual(jasmine.any(Array));
+ expect(this.subject[0] instanceof HTMLElement).toBe(true);
+ });
+
+ it("finds all elements", function () {
+ this.expression = "input";
+ expect(this.subject.length).toEqual($$("input").length);
+ });
+
+ it("finds DOM element", function () {
+ this.expression = "#no-options";
+ expect(this.subject[0] instanceof HTMLElement).toBe(true);
+ });
+
+ it("finds by id", function () {
+ this.expression = "#no-options";
+ expect(this.subject[0].id).toEqual("no-options");
+ });
+
+ it("finds by class name", function () {
+ this.expression = ".simple-input";
+ expect(this.subject[0].id).toEqual("no-options");
+ });
+
+ it("finds by tag name", function () {
+ this.expression = "datalist";
+ expect(this.subject[0].id).toEqual("list");
+ });
+ }
+});
diff --git a/test/specHelper.js b/test/specHelper.js
index 7396e6d..f00202a 100644
--- a/test/specHelper.js
+++ b/test/specHelper.js
@@ -5,6 +5,10 @@ function $ (str, context) {
return (context || fixture.el).querySelector(str);
}
+function $$(str, context) {
+ return (context || fixture.el).querySelectorAll(str);
+}
+
// bundled fixture load/cleanup
$.fixture = function (fixtureName) {
beforeEach(function () {