Print Shortlink

Unit testing Ext JS4 using Jasmine

Ext JS4 recommends unit testing of the application using Jasmine library. The article can be found here.

Given below are some screenshots of a simple application that has been unit tested with Jasmine. The application is implemented in the MVC style.

The page just contains a combobox of countries as shown below.

The test page that contains the results of the test-cases created using Jasmine is shown below.

A sample unit testing code using Jasmine is shown below

describe("Test Country Store",function(){
	var store = null;
	beforeEach(function(){
		store = Application.getStore("CountryStore");
		waitsFor(function(){ 
			 	return !store.isLoading(); },"load never completed",4000
		);
	});

	it("test Country Store data",function(){
		expect(store).toBeDefined();
		expect(store).toBeTruthy();
	});
	it("test Country Store data country",function(){
		expect(store.getCount()).toEqual(3);
	});
});

The syntax for Jasmine is similar to JUnit with expect() functions similar to the assert methods. You can refer to this site for more information about Jasmine API.

The complete code, as an Eclipse project, can be viewed in https://github.com/prabhu-durasoft/Unit_Testing_ExtJS4_Using_JASMINE_1

Leave a Reply