Created
September 11, 2012 04:36
-
-
Save blakehaswell/3695990 to your computer and use it in GitHub Desktop.
Jasmine Test Suite Abstraction
This file contains hidden or 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
TestSuite.add({ | |
name: "List transformer", | |
getHtml: function () { | |
var html = []; | |
html.push("<ul class=\"unorderedList\">"); | |
html.push("<li>A list item</li>"); | |
html.push("<li>A second list item</li>"); | |
html.push("</ul>"); | |
html.push("<ol class=\"orderedList\">"); | |
html.push("<li>A list item</li>"); | |
html.push("<li>A second list item</li>"); | |
html.push("</ol>"); | |
return html.join(""); | |
}, | |
tests: function () { | |
beforeEach(function () { | |
this.$(".unorderedList, .orderedList").transformList(); | |
}); | |
it("Transforms unordered lists into ordered lists", function () { | |
expect(this.$("ol.unorderedList").length).toBe(1); | |
}); | |
it("Transforms ordered lists into unordered lists", function () { | |
expect(this.$("ul.orderedList").length).toBe(1); | |
}); | |
} | |
}); |
This file contains hidden or 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
$.each(TestSuite.suites, function (index, suite) { | |
suite.run(); | |
}); |
This file contains hidden or 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
var TestSuite = function (name, html, tests) { | |
this.name = name; | |
this.html = html; | |
this.tests = tests; | |
}; | |
TestSuite.prototype = { | |
run: function () { | |
describe(this.name, function () { | |
beforeEach(function () { | |
this.$el = $("<div></div>").append(this.html); | |
this.$el.appendTo("body"); | |
}); | |
afterEach(function () { | |
this.$el.remove(); | |
}); | |
this.tests.call(this); | |
}); | |
}, | |
$: function (selector) { | |
return $(selector, this.$el); | |
} | |
}; | |
TestSuite.suites = []; | |
TestSuite.add = function (obj) { | |
var name = obj.name; | |
var html = obj.getHtml(); | |
var tests = obj.tests; | |
TestSuite.suites.push(new TestSuite(name, html, tests)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment