Skip to content

Commit

Permalink
Merge pull request #28 from zikicm/master
Browse files Browse the repository at this point in the history
Properties (getters and setters) unit tests
  • Loading branch information
tnhu committed Apr 28, 2015
2 parents 72decec + 6198a06 commit 0b653f3
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/tests/core.js
Expand Up @@ -368,6 +368,74 @@ test("Static methods should be inherited accordingly", function() {
equal(bar.barStaticMethod, undefined, "Static method should not be on instance");
});

test("Properties - getters and setters", function() {

var Person = Class({
constructor : function(name) {
this._name = name;
},
name : {
get : function() {
return this._name;
},
set : function(value) {
this._name = value;
}
}
});

var person = new Person("Milos");

equal(person.name, "Milos", "Invalid property getter");

person.name = "Boki";

equal(person.name, "Boki", "Invalid property setter");

});

test("Properties - getters and setters - inheritance", function() {

var Person = Class({
constructor : function(name) {
this._name = name;
},
name : {
get : function() {
return this._name;
},
set : function(value) {
this._name = value;
}
}
});

var Student = Class(Person, {
constructor : function(name, age) {
Student.$super.call(this, name);
this._age = age;
},
age : {
get : function() {
return this._age;
},
set : function(value) {
this._age = value;
}
}
});

var student = new Student("Mia", 18);

equal(student.name, "Mia", "Bad property inheritance");

student.name = "Persa";

equal(student.name, "Persa", "Bad property inheritance");
equal(student.age, 18, "Invalid property getter");

});

test("Singleton class", function() {
var Foo = Class({
$singleton: true,
Expand Down

0 comments on commit 0b653f3

Please sign in to comment.