Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test constructor property
  • Loading branch information
polotek committed Apr 1, 2013
1 parent cbab0ba commit 5999ed7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests.js
Expand Up @@ -62,8 +62,31 @@ test('ctor still supports "new" but doesn\'t need it', function(t) {
t.equal(p.sayHello, Person.prototype.sayHello);

p = Person('Marco', 'polotek');
t.ok(p instanceof Person);
t.ok(p instanceof Ctor);
t.equal(p.sayHello, Person.prototype.sayHello);

t.end();
});

test('ctor adds non-enumerable "contructor" property to prototype', function(t) {
var Person = Ctor.extend({
constructor: function Person(name, nickname) {
this.name = name;
this.nickname = nickname;
}
, sayHello: function() {
return "Hey, I'm " + this.name + '. But you can call me ' + this.nickname;
}
});

var p = Person.create('Marco', 'polotek')
, proto = Object.getPrototypeOf(p);

t.equal(p.hasOwnProperty('constructor'), false);
t.equal(proto.constructor, Person);

var desc = Object.getOwnPropertyDescriptor(proto, 'constructor');
t.equal(desc.enumerable, false);

t.end();
});

0 comments on commit 5999ed7

Please sign in to comment.