Post image for tijasmine (jasmine BDD for Appcelerator Titanium) turns 1.0.0

tijasmine (jasmine BDD for Appcelerator Titanium) turns 1.0.0

by Bill Dawson on 11 May 2013

This is just an update regarding my tijasmine Titanium wrapper for the Jasmine JavaScript BDD library.

At the time that I first mentioned tijasmine, it was based on the alpha version of Jasmine 2.0. I’ve since changed it so that it’s now based on the most current public release of Jasmine, which is 1.3.1. At the time of this writing, if you visit the Jasmine site, you see the page of documentation with several example test specs, and those are running against 1.3.1. So I thought it would make more sense (obviously) to base tijasmine on the documented version of Jasmine!

I’ve updated the console reporter so that it indents nested specs. Also, at the end of the test run it will now show you a summary of all of the failing tests so that you don’t need to scroll up through the console to find them:


I/TiAPI   ( 1928):  ============================================================
E/TiAPI   ( 1928):  THERE WERE FAILURES!
E/TiAPI   ( 1928):  ============================================================
E/TiAPI   ( 1928):  Recap of failing specs:
E/TiAPI   ( 1928):  ------------------------------------------------------------
E/TiAPI   ( 1928):  My First Suite shows what a failure does. - Expected false to equal true.
E/TiAPI   ( 1928):  My First Suite of another spec shows what a failure does. - Expected false to equal true.
E/TiAPI   ( 1928):  ------------------------------------------------------------

Additionally, I fixed the broken async testing capabilities. In fact, the example app now includes the same set of specs that Jasmine’s documentation site is using, so you can see the async tests in action if you run it. All of the specs therein pass under tijasmine, which gave me the confidence to go ahead and tag the current tijasmine code base as version 1.0.0.

Here is a short example of testing something asynchronous in Titanium using tijasmine:

require("/tijasmine/tijasmine").infect(this);

describe("Async tests", function() {
	var openFlag = false,
		closeFlag = false;

	it("can ensure a Titanium event fires", function() {
		var w = Ti.UI.createWindow();

		// The function that will kickoff
		// something asynchronous.
		runs(function() {
			w.addEventListener("close", function() {
				closeFlag = true;
				w = null;
			});

			w.addEventListener("open", function() {
				openFlag = true;
				w.close();
			});

			w.open();
		});

		// The latch function, which will
		// continuously be called until:
		// a) It returns true; OR
		// b) It times out.
		waitsFor(function() {
			return openFlag && closeFlag;
		}, 1000); // timeout

		// Function that runs after the
		// latch function releases, can
		// check an expectation.
		runs(function() {
			expect(w).toBeNull();
		});
	});
});

I hope you can take advantage of tijasmine and that it helps you practice BDD/TDD with your Titanium projects. Remember, feel free to alert me of issues and/or fork and submit pull requests!

[Photo credit: “Birthday cake” from Flickr user anemoneprojectors. License: Creative Commons Attribution-ShareAlike 2.0 Generic (CC BY-SA 2.0)].

Comments on this entry are closed.

Previous post:

Next post: