Permalink
Browse files

restore proper tests from the 3.0beta branch

  • Loading branch information...
1 parent e79d8d7 commit 2a5f9443044c6dc993217b7910b3e8aac81a2dec Ian Maffett committed Jun 30, 2015
View
0 test/actionSheet.test.js 100644 → 100755
No changes.
View
@@ -1,22 +0,0 @@
-require("./chai.helper");
-var domHelper = require("./dom.helper");
-
-describe("addClass", function () {
- // set up the DOM and some global variables
- beforeEach(function () {
- domHelper(
- "<div id=\"single1\" class=\"red\"></div>" +
- "<div id=\"single2\" class=\"red\"></div>"
- );
- });
-
- it("should append a single new class", function () {
- $("#single1").addClass("black");
- $("#single1").attr("class").should.equal("red black");
- });
-
- it("should not append a class if it already exists on an element", function () {
- $("#single2").addClass("red");
- $("#single2").attr("class").should.equal("red");
- });
-});
View
0 test/afui.test.js 100644 → 100755
No changes.
View
@@ -1,223 +0,0 @@
-require("./chai.helper");
-var domHelper = require("./dom.helper");
-var HttpFake = require("./http-fake.helper");
-var XMLHttpRequest = require("./http-fake-xmlhttprequest.helper");
-
-// NB sinon has a fake XMLHTTPRequest object, but it doesn't
-// work properly with node.js;
-// see https://groups.google.com/forum/#!topic/sinonjs/yD8Q9OjtFvc
-
-describe("ajax", function () {
- var originalXmlHttpRequest;
- var server = HttpFake.createServer();
-
- // we need to refer to this from the tests, but we allow
- // the server to randomly get a port before setting it
- var host;
-
- before(function (done) {
- domHelper(
- "<div id=\"foo\">" +
- "</div>"
- );
-
- // replace jsdom's XMLHttpRequest with
- // node-xmlhttprequest, to support POST requests
- originalXmlHttpRequest = window.XMLHttpRequest;
- window.XMLHttpRequest = XMLHttpRequest;
-
- server.start(function () {
- host = "localhost:" + server.port;
- done.apply(null, arguments);
- });
- });
-
- afterEach(function () {
- server.clearFakes();
- });
-
- after(function (done) {
- window.XMLHttpRequest = originalXmlHttpRequest;
- server.stop(done);
- });
-
- it("should do a GET request to a specified url", function (done) {
- // this is what we expect the request to look like
- var requestMatcher = {
- method: "GET",
- path: "/",
- query: {a: "1", b: "2"},
- host: "localhost",
- headers: {
- "x-bloop": "glong"
- }
- };
-
- // this is what we send back if we get the expected request
- var response = { data: "hello world" };
-
- server.registerFake(response, requestMatcher);
-
- $.ajax({
- type: "GET",
- url: "http://" + host + "/",
- data: "a=1&b=2",
- dataType: "text",
- headers: {
- "X-bloop": "glong"
- },
- success: function (data) {
- data.should.equal("hello world");
- done();
- },
- error: function (xhr) {
- done(new Error(xhr.responseText));
- }
- });
- });
-
- it("should do a POST request to a specified url", function (done) {
- var postData = {a: 1, b: 2};
-
- // this is what we expect the request to look like
- var requestMatcher = {
- method: "POST",
- path: "/save",
- host: "localhost",
- headers: {
- "content-type": "application/x-www-form-urlencoded"
- },
- body: { a: "1", b: "2" }
- };
-
- // this is what we send back if we get the expected request
- var response = { data: "OK" };
-
- server.registerFake(response, requestMatcher);
-
- $.ajax({
- type: "POST",
- url: "http://" + host + "/save",
- contentType: "application/x-www-form-urlencoded",
- data: postData,
- success: function (responseText) {
- responseText.should.equal("OK");
- done();
- },
- error: function (xhr) {
- done(new Error(xhr.responseText));
- }
- });
- });
-
- it("should do a GET request for XML to a specified url", function (done) {
- var requestMatcher = {
- method: "GET",
- path: "/",
- query: { x: "10", y: "20", z: "30" },
- host: "localhost"
- };
-
- var xml = "<?xml version=\"1.0\"><top/>";
- var response = { data: xml };
-
- server.registerFake(response, requestMatcher);
-
- $.ajax({
- type: "GET",
- url: "http://" + host + "/?x=10",
- data: "y=20&z=30",
- dataType: "xml",
- success: function (data) {
- data.should.equal(xml);
- done();
- },
- error: function (xhr) {
- done(new Error(xhr.responseXML));
- }
- });
- });
-
- it("should do a json request and parse the response", function (done) {
- var requestMatcher = {
- method: "GET",
- path: "/",
- host: "localhost"
- };
-
- var responseData = {hi: "world", nice: "to see you"};
- var response = { data: JSON.stringify(responseData) };
-
- server.registerFake(response, requestMatcher);
-
- $.ajax({
- type: "GET",
- url: "http://" + host + "/",
- dataType: "json",
- success: function (data) {
- data.should.eql(responseData);
- done();
- },
- error: function (xhr) {
- done(new Error(xhr.responseText));
- }
- });
- });
-
- it("should call error callback if request fails", function (done) {
- var requestMatcher = {
- method: "GET",
- path: "/",
- host: "localhost"
- };
-
- var response = { status: 503 };
-
- server.registerFake(response, requestMatcher);
-
- $.ajax({
- type: "GET",
- url: "http://" + host + "/",
-
- success: function (data) {
- done(new Error("success cb should not be called"));
- },
-
- error: function (xhr, message) {
- xhr.status.should.equal(503);
- message.should.equal("error");
- done();
- }
- });
- });
-
- it("should call error callback if request times out", function (done) {
- var requestMatcher = {
- method: "GET",
- path: "/",
- host: "localhost"
- };
-
- // response should still error because it times out,
- // even though the status code is 200
- var response = { status: 200, pause: 2000, data: "OK" };
-
- server.registerFake(response, requestMatcher);
-
- $.ajax({
- type: "GET",
- url: "http://" + host + "/",
-
- timeout: 100,
-
- success: function (data) {
- done(new Error("success cb should not be called"));
- },
-
- error: function (xhr, message) {
- message.should.equal("timeout");
- done();
- }
- });
- });
-});
View
0 test/animation.test.js 100644 → 100755
No changes.
View
@@ -1,46 +0,0 @@
-require("./chai.helper");
-var domHelper = require("./dom.helper");
-
-describe("appendTo", function () {
- beforeEach(function () {
- domHelper(
- "<div id=\"appendToTest\"></div>"
- );
- });
-
- it("should append a string to an element", function () {
- $("<span class=\"important\"></span>").appendTo("#appendToTest");
- document.getElementById("appendToTest").childNodes.length.should.equal(1);
- });
-
- it("should append a DOM element", function () {
- var elt = document.createElement("p");
- elt.setAttribute("id", "intro");
- elt.textContent = "hello";
-
- $(elt).appendTo("#appendToTest");
-
- var children = document.getElementById("appendToTest").childNodes;
- children.length.should.equal(1);
- children[0].getAttribute("id").should.equal("intro");
- children[0].textContent.should.equal("hello");
- });
-
- it("should append multiple DOM elements in the correct order", function () {
- var elt1 = document.createElement("p");
- elt1.setAttribute("id", "end");
- elt1.textContent = "world";
-
- var elt2 = document.createElement("p");
- elt2.setAttribute("id", "more-end");
- elt2.textContent = "goodbye";
-
- $(elt1).appendTo("#appendToTest");
- $(elt2).appendTo("#appendToTest");
-
- var children = document.getElementById("appendToTest").childNodes;
- children.length.should.equal(2);
- children[1].getAttribute("id").should.equal("more-end");
- children[1].textContent.should.equal("goodbye");
- });
-});
View
@@ -1,103 +0,0 @@
-require("./chai.helper");
-var domHelper = require("./dom.helper");
-
-describe("attr", function () {
- beforeEach(function () {
- domHelper(
- "<div id=\"single1\" class=\"red\" data-spong=\"bang\"></div>" +
- "<div id=\"single2\" class=\"red\" data-spong=\"bloing\"></div>"
- );
- });
-
- it("should set an attribute on a collection of elements", function () {
- var divs = $("div");
- divs.attr("data-foo", "bar");
-
- var rawDivs = document.querySelectorAll("div");
-
- for (var i = 0; i < rawDivs.length; i += 1) {
- rawDivs[i].getAttribute("data-foo").should.equal("bar");
- }
- });
-
- it("should set attributes from an object on a collection of elements", function () {
- var divs = $("div");
- divs.attr({
- "data-foo": "bar",
- "data-ex": "why",
- "data-alpha": "zed"
- });
-
- var rawDivs = document.querySelectorAll("div");
-
- for (var i = 0; i < rawDivs.length; i += 1) {
- rawDivs[i].getAttribute("data-foo").should.equal("bar");
- rawDivs[i].getAttribute("data-ex").should.equal("why");
- rawDivs[i].getAttribute("data-alpha").should.equal("zed");
- }
- });
-
- it("should set a (pseudo) attribute to a function, object or array", function () {
- // function
- var fn = function () {
- return "bar";
- };
-
- $(".red").attr("data-foo", fn);
- $(document.getElementById("single1")).attr("data-foo").should.equal(fn);
- $(document.getElementById("single2")).attr("data-foo").should.equal(fn);
-
- // object
- var obj = {
- a: 1,
- b: 2
- };
-
- $(".red").attr("data-foo", obj);
- $(document.getElementById("single1")).attr("data-foo").should.equal(obj);
- $(document.getElementById("single2")).attr("data-foo").should.equal(obj);
-
- // array
- var arr = ["a", "b", "c"];
-
- $(".red").attr("data-foo", arr);
- $(document.getElementById("single1")).attr("data-foo").should.equal(arr);
- $(document.getElementById("single2")).attr("data-foo").should.equal(arr);
- });
-
- it("should remove an attribute if value is set to null", function () {
- $(".red").attr("data-greet", "hello");
- $(".red").attr("data-greet", null);
-
- var elt1 = document.getElementById("single1");
- var value1 = elt1.getAttribute("data-greet");
- (value1 === null).should.be.true
-
- var elt2 = document.getElementById("single2");
- var value2 = elt2.getAttribute("data-greet");
- (value2 === null).should.be.true
- });
-
- it("should remove a (pseudo) attribute if value is set to null", function () {
- $(".red").attr("data-greet", {a: 1, b: 2});
- $(".red").attr("data-greet", null);
-
- var elt1 = document.getElementById("single1");
- var value1 = elt1.getAttribute("data-greet");
- (value1 === null).should.be.true
-
- var elt2 = document.getElementById("single2");
- var value2 = elt2.getAttribute("data-greet");
- (value2 === null).should.be.true
- });
-
- it("should get an attribute's value from a single element", function () {
- var actual = $("#single1").attr("data-spong");
- actual.should.equal("bang");
- });
-
- it("should get the first element's attribute value if called on an af collection", function () {
- var actual = $(".red").attr("data-spong");
- actual.should.equal("bang");
- });
-});
Oops, something went wrong.

0 comments on commit 2a5f944

Please sign in to comment.