unit testing for events

This commit is contained in:
Ezequiel Bergamaschi 2014-09-27 14:35:49 -03:00
parent 27149b0870
commit 98d9d877a2
3 changed files with 50 additions and 4 deletions

View File

@ -56,7 +56,6 @@
<sourceIncludes>
<include>Functions.js</include>
</sourceIncludes>
<browserVersion>CHROME</browserVersion>
</configuration>
</plugin>

View File

@ -257,7 +257,7 @@
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.3.1.4</version>
<version>1.3.1.5</version>
<executions>
<execution>
<goals>
@ -266,12 +266,16 @@
</execution>
</executions>
<configuration>
<!--
<browserVersion>FIREFOX_3_6</browserVersion>
<webDriverClassName>org.openqa.selenium.firefox.FirefoxDriver</webDriverClassName>
-->
<sourceIncludes>
<sourceInclude>libraries/mootools/mootools-core-1.4.5-full-nocompat.js</sourceInclude>
<sourceInclude>header.js</sourceInclude>
<include>libraries/mootools/mootools-core-1.4.5-full-nocompat-yc.js</include>
<include>header.js</include>
<include>libraries/jquery/jquery-2.1.0.min.js</include>
<include>Events.js</include>
</sourceIncludes>
<specExcludes>
<exclude>static/test/*.js</exclude>

View File

@ -0,0 +1,43 @@
var TestClass = new Class({
Extends: mindplot.Events,
getEvents: function() {
return this.$events;
},
removeEvents: function() {
this.$events = {};
}
});
// Test class and variables
var expectedChangeFn1 = function () {return 'change1';};
var expectedChangeFn2 = function () {return 'change2';};
var expectedLoadFn = function() {return 'loaded';};
var myTestClass = new TestClass();
describe("Events class suite", function() {
afterEach(function() {
myTestClass.removeEvents();
});
it("addEventTest", function() {
expect(myTestClass.getEvents()).toEqual({});
myTestClass.addEvent('change', expectedChangeFn1);
expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn1]});
myTestClass.addEvent('change', expectedChangeFn2);
expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn1, expectedChangeFn2]});
myTestClass.addEvent('load', expectedLoadFn);
expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn1, expectedChangeFn2], load: [expectedLoadFn]});
});
it("removeEventTest", function() {
expect(myTestClass.getEvents()).toEqual({});
myTestClass.addEvent('change', expectedChangeFn1);
myTestClass.addEvent('change', expectedChangeFn2);
expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn1, expectedChangeFn2]});
myTestClass.removeEvent('change', expectedChangeFn1);
expect(myTestClass.getEvents()).toEqual({change: [expectedChangeFn2]});
});
});