Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3435a96
commit e14da17
Showing
8 changed files
with
132 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
BIN=node_modules/.bin/ | ||
MOCHA=$(BIN)mocha | ||
WATCHY=$(BIN)watchy | ||
TEST=$(MOCHA) --colors --recursive -R spec | ||
|
||
test-w: | ||
NODE_ENV=test $(WATCHY) -w test,underscore-inherit.js -- $(TEST) | ||
|
||
test: | ||
NODE_ENV=test $(TEST) | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
{ | ||
"name": "underscore-inherit", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "Casey Foster <c@sey.me>", | ||
"main": "underscore-inherit", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/caseywebdev/underscore-inherit" | ||
}, | ||
"devDependencies": { | ||
"underscore": "x" | ||
"chai": "x", | ||
"mocha": "x", | ||
"underscore": "x", | ||
"watchy": "x" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"boss": true, | ||
"browser": true, | ||
"expr": true, | ||
"eqnull": true, | ||
"indent": 2, | ||
"latedef": true, | ||
"maxlen": 80, | ||
"newcap": false, | ||
"node": true, | ||
"strict": false, | ||
"sub": true, | ||
"trailing": true, | ||
"unused": true, | ||
"white": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
var _ = require('underscore'); | ||
require('..'); | ||
var expect = require('chai').expect; | ||
|
||
describe('A simple "class"', function () { | ||
var Klass = _.inherit({ | ||
constructor: function () { this.instanceProp = 'a'; }, | ||
protoProp: 'b' | ||
}, { | ||
staticProp: 'c' | ||
}); | ||
|
||
it('is a function', function () { | ||
expect(Klass).to.be.a('function'); | ||
}); | ||
|
||
it('is inherited by its child', function () { | ||
expect(new Klass()).to.be.instanceof(Klass); | ||
}); | ||
|
||
it('copies static properties', function () { | ||
expect(Klass).to.have.property('staticProp', 'c'); | ||
}); | ||
|
||
it('copies prototype properties', function () { | ||
expect(Klass.prototype).to.have.property('protoProp', 'b'); | ||
}); | ||
|
||
it('equals the special constructor property', function () { | ||
expect(Klass.prototype.constructor).to.equal(Klass); | ||
}); | ||
|
||
it('invokes the constructor on instance creation', function () { | ||
expect(new Klass()).to.have.property('instanceProp', 'a'); | ||
}); | ||
}); | ||
|
||
describe('Single inheritance', function () { | ||
var KlassA = _.inherit({ | ||
aProtoMethod: function () {} | ||
}, { | ||
aStaticMethod: function () {} | ||
}); | ||
|
||
var KlassB = _.inherit(KlassA); | ||
|
||
it('works with instanceof', function () { | ||
expect(new KlassB()).to.be.instanceOf(KlassA); | ||
}); | ||
|
||
it("inherits the parent class's static methods", function () { | ||
expect(KlassB).to.have.property('aStaticMethod'); | ||
}); | ||
|
||
it("inherits the parent class's prototype methods", function () { | ||
expect(KlassB.prototype).to.have.property('aProtoMethod'); | ||
}); | ||
}); | ||
|
||
describe('Multiple inheritance', function () { | ||
var KlassA = _.inherit({ | ||
theProtoMethod: function () {} | ||
}); | ||
|
||
var KlassB = _.inherit({ | ||
theProtoMethod: function () {} | ||
}); | ||
|
||
var KlassC = _.inherit(KlassA, KlassB); | ||
|
||
it('works with instanceof', function () { | ||
expect(new KlassC()).to.be.instanceOf(KlassA).and.instanceOf(KlassB); | ||
}); | ||
|
||
it("inherits the most recent parent class's prototype methods", function () { | ||
expect(KlassB.prototype).to.have | ||
.property('theProtoMethod', KlassB.theProtoMethod); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters