From a6c150219e3dc43b91086b91fe8a46ff2f6109c2 Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Fri, 9 Dec 2016 22:54:38 -0800 Subject: [PATCH 01/12] Clean up --- src/index.js | 13 +------------ src/spec.js | 1 - 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/index.js b/src/index.js index 5237ff4..a07ffec 100644 --- a/src/index.js +++ b/src/index.js @@ -4,23 +4,12 @@ export function double ( x ) { export function doubleXTimes ( x, num ) { let result = x; - for ( let i = 1; i <= num; i++ ) { - // result = result * 2; result = double( result ); } - return result; } export function doubleEach ( arr ) { - let result = arr.map( double ); - - // const result = arr.map( x => double( x ) ); - // const result = arr.map( function ( x ) { - // return double( x ); - // }); - - return result; + return arr.map( double ); } - diff --git a/src/spec.js b/src/spec.js index 3e22930..96cc039 100644 --- a/src/spec.js +++ b/src/spec.js @@ -27,4 +27,3 @@ test( 'doubleEach', function ( test ) { test.end(); }); - From 46235f35f870d64c370d79ac3bca6823aa60bd96 Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sat, 10 Dec 2016 00:11:28 -0800 Subject: [PATCH 02/12] first-tests --- src/index.js | 2 ++ src/spec.js | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index a07ffec..976b40a 100644 --- a/src/index.js +++ b/src/index.js @@ -13,3 +13,5 @@ export function doubleXTimes ( x, num ) { export function doubleEach ( arr ) { return arr.map( double ); } + +export function Animal() {}; diff --git a/src/spec.js b/src/spec.js index 96cc039..0f40d6d 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,5 +1,5 @@ import test from 'tape'; -import { double, doubleXTimes, doubleEach } from './index'; +import { double, doubleXTimes, doubleEach, Animal } from './index'; test( 'double fn', function ( test ) { const actual = double( 5 ); @@ -27,3 +27,10 @@ test( 'doubleEach', function ( test ) { test.end(); }); + +test('Animal exists', function(test) { + const animal = new Animal(); + + test.ok( animal instanceof Animal, 'should create an instance of Animal' ); + test.end(); +}); From 79270b892216795a436b5b687db6ff496b557570 Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sat, 10 Dec 2016 00:13:35 -0800 Subject: [PATCH 03/12] Adds speak method to Animal --- src/index.js | 4 ++++ src/spec.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 976b40a..6ddb06d 100644 --- a/src/index.js +++ b/src/index.js @@ -15,3 +15,7 @@ export function doubleEach ( arr ) { } export function Animal() {}; + +Animal.prototype.speak = function(sound) { + return sound; +} diff --git a/src/spec.js b/src/spec.js index 0f40d6d..d97d2d4 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,5 +1,5 @@ import test from 'tape'; -import { double, doubleXTimes, doubleEach, Animal } from './index'; +import { double, doubleXTimes, doubleEach, Animal, Reptile } from './index'; test( 'double fn', function ( test ) { const actual = double( 5 ); @@ -34,3 +34,12 @@ test('Animal exists', function(test) { test.ok( animal instanceof Animal, 'should create an instance of Animal' ); test.end(); }); + +test('Animal has speak method', function(test) { + const animal = new Animal(); + const expected = 'generic sound'; + const actual = animal.speak(expected); + + test.equal( actual, expected, 'should make a generic sound when it speaks' ); + test.end(); +}); From 53123f6cb0ebdb5ce61f4468b1a1ee79367bcb5a Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sat, 10 Dec 2016 00:44:50 -0800 Subject: [PATCH 04/12] Adds Reptile and Primate --- src/index.js | 8 ++++++++ src/spec.js | 26 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 6ddb06d..9aa2ebb 100644 --- a/src/index.js +++ b/src/index.js @@ -19,3 +19,11 @@ export function Animal() {}; Animal.prototype.speak = function(sound) { return sound; } + +export function Reptile() {}; + +Reptile.prototype = Object.create(Animal.prototype); + +export function Primate() {}; + +Primate.prototype = Object.create(Animal.prototype); diff --git a/src/spec.js b/src/spec.js index d97d2d4..55ac874 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,5 +1,5 @@ import test from 'tape'; -import { double, doubleXTimes, doubleEach, Animal, Reptile } from './index'; +import { double, doubleXTimes, doubleEach, Animal, Reptile, Primate } from './index'; test( 'double fn', function ( test ) { const actual = double( 5 ); @@ -43,3 +43,27 @@ test('Animal has speak method', function(test) { test.equal( actual, expected, 'should make a generic sound when it speaks' ); test.end(); }); + +test('Checks Animal inheritance', function(test) { + let actual, expected; + + const reptile = new Reptile(); + + test.ok( reptile instanceof Reptile, 'should be an instance of Reptile' ); + test.ok( reptile instanceof Animal, 'should be an instance of Animal' ); + + expected = Reptile.SOUND; + actual = reptile.speak(); + test.equal( actual, expected, 'should make a reptile sound when it speaks' ); + + const primate = new Primate(); + + test.ok( primate instanceof Primate, 'should be an instance of Primate' ); + test.ok( primate instanceof Animal, 'should be an instance of Animal' ); + + expected = Primate.SOUND; + actual = primate.speak(); + test.equal( actual, expected, 'should make a primate sound when it speaks' ); + + test.end(); +}); From a3bda501b227729510abea1667ee2dd0034eff2d Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sat, 10 Dec 2016 00:48:30 -0800 Subject: [PATCH 05/12] Adds human --- src/index.js | 4 ++++ src/spec.js | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9aa2ebb..44d977f 100644 --- a/src/index.js +++ b/src/index.js @@ -27,3 +27,7 @@ Reptile.prototype = Object.create(Animal.prototype); export function Primate() {}; Primate.prototype = Object.create(Animal.prototype); + +export function Human() {}; + +Human.prototype = Object.create(Primate.prototype); diff --git a/src/spec.js b/src/spec.js index 55ac874..e079d9a 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,5 +1,5 @@ import test from 'tape'; -import { double, doubleXTimes, doubleEach, Animal, Reptile, Primate } from './index'; +import { double, doubleXTimes, doubleEach, Animal, Reptile, Primate, Human } from './index'; test( 'double fn', function ( test ) { const actual = double( 5 ); @@ -67,3 +67,20 @@ test('Checks Animal inheritance', function(test) { test.end(); }); + +test('Adds Human', function(test) { + let actual, expected; + + const human = new Human(); + + test.ok( human instanceof Human, 'should be an instance of Human' ); + test.ok( human instanceof Primate, 'should be an instance of Primate' ); + test.ok( human instanceof Animal, 'should be an instance of Animal' ); + + const message = 'hello'; + expected = message; + actual = human.speak( message ); + test.equal( actual, expected, 'should speak what it is asked to speak' ); + + test.end(); +}); From e6a714a42ed50615003a3c01a611bf8b2f7e0118 Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sat, 10 Dec 2016 11:04:16 -0800 Subject: [PATCH 06/12] Adds stampit --- package.json | 3 ++- src/index.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a87fa31..3af6dea 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "license": "MIT", "dependencies": { "babel-preset-es2015": "^6.13.2", - "babel-preset-stage-0": "^6.5.0" + "babel-preset-stage-0": "^6.5.0", + "stampit": "^3.0.6" }, "devDependencies": { "babel-register": "^6.14.0", diff --git a/src/index.js b/src/index.js index 44d977f..d3b3c76 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +import stampit from 'stampit'; + export function double ( x ) { return x * 2; } From 82e9b36cd07f184427bc2c5416e668cd79be7bb6 Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sat, 10 Dec 2016 19:04:50 -0800 Subject: [PATCH 07/12] Playing with isStamp() --- src/index.js | 26 ++++++++------------- src/spec.js | 65 +++++++++------------------------------------------- 2 files changed, 21 insertions(+), 70 deletions(-) diff --git a/src/index.js b/src/index.js index d3b3c76..9480712 100644 --- a/src/index.js +++ b/src/index.js @@ -16,20 +16,14 @@ export function doubleEach ( arr ) { return arr.map( double ); } -export function Animal() {}; - -Animal.prototype.speak = function(sound) { - return sound; -} - -export function Reptile() {}; - -Reptile.prototype = Object.create(Animal.prototype); - -export function Primate() {}; - -Primate.prototype = Object.create(Animal.prototype); - -export function Human() {}; +export const Animal = stampit({ + methods: { + speak(sound) { + return sound; + } + } +}); -Human.prototype = Object.create(Primate.prototype); +export const Reptile = stampit.compose(Animal); +export const Primate = stampit.compose(Animal); +export const Human = stampit.compose(Primate); diff --git a/src/spec.js b/src/spec.js index e079d9a..0a9af6a 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,5 +1,7 @@ import test from 'tape'; -import { double, doubleXTimes, doubleEach, Animal, Reptile, Primate, Human } from './index'; +import { double, doubleXTimes, doubleEach, Animal, Reptile, Primate, Human} from './index'; +import stampit from 'stampit'; +import isStamp from 'stampit/isStamp'; test( 'double fn', function ( test ) { const actual = double( 5 ); @@ -29,58 +31,13 @@ test( 'doubleEach', function ( test ) { }); test('Animal exists', function(test) { - const animal = new Animal(); - - test.ok( animal instanceof Animal, 'should create an instance of Animal' ); - test.end(); -}); - -test('Animal has speak method', function(test) { - const animal = new Animal(); - const expected = 'generic sound'; - const actual = animal.speak(expected); - - test.equal( actual, expected, 'should make a generic sound when it speaks' ); - test.end(); -}); - -test('Checks Animal inheritance', function(test) { - let actual, expected; - - const reptile = new Reptile(); - - test.ok( reptile instanceof Reptile, 'should be an instance of Reptile' ); - test.ok( reptile instanceof Animal, 'should be an instance of Animal' ); - - expected = Reptile.SOUND; - actual = reptile.speak(); - test.equal( actual, expected, 'should make a reptile sound when it speaks' ); - - const primate = new Primate(); - - test.ok( primate instanceof Primate, 'should be an instance of Primate' ); - test.ok( primate instanceof Animal, 'should be an instance of Animal' ); - - expected = Primate.SOUND; - actual = primate.speak(); - test.equal( actual, expected, 'should make a primate sound when it speaks' ); - - test.end(); -}); - -test('Adds Human', function(test) { - let actual, expected; - - const human = new Human(); - - test.ok( human instanceof Human, 'should be an instance of Human' ); - test.ok( human instanceof Primate, 'should be an instance of Primate' ); - test.ok( human instanceof Animal, 'should be an instance of Animal' ); - - const message = 'hello'; - expected = message; - actual = human.speak( message ); - test.equal( actual, expected, 'should speak what it is asked to speak' ); - + const animal = stampit().compose(Animal); + console.log( animal().speak('bark bark bark') ); + // console.log('4. Animalxxxx', Animal.hasCreated(animal)); + console.log('1. animal', animal); + // console.log('2. isStamp(Animal)', isStamp(Animal) ); + // console.log('3. isstamp(animal)', isStamp(animal) ); + test.ok( isStamp(Animal), 'Animal is a stamp' ); + test.ok( '?', 'animal is an instance of Animal' ); test.end(); }); From e0da8a04f071e30f7d7c807a7904eb276b175688 Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sun, 11 Dec 2016 17:48:47 -0800 Subject: [PATCH 08/12] Reset / cleanup --- src/index.js | 29 ++--------------------------- src/spec.js | 39 ++++----------------------------------- 2 files changed, 6 insertions(+), 62 deletions(-) diff --git a/src/index.js b/src/index.js index 9480712..824c285 100644 --- a/src/index.js +++ b/src/index.js @@ -1,29 +1,4 @@ import stampit from 'stampit'; +// -export function double ( x ) { - return x * 2; -} - -export function doubleXTimes ( x, num ) { - let result = x; - for ( let i = 1; i <= num; i++ ) { - result = double( result ); - } - return result; -} - -export function doubleEach ( arr ) { - return arr.map( double ); -} - -export const Animal = stampit({ - methods: { - speak(sound) { - return sound; - } - } -}); - -export const Reptile = stampit.compose(Animal); -export const Primate = stampit.compose(Animal); -export const Human = stampit.compose(Primate); +export const Animal = stampit(); diff --git a/src/spec.js b/src/spec.js index 0a9af6a..2fa2377 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,43 +1,12 @@ import test from 'tape'; -import { double, doubleXTimes, doubleEach, Animal, Reptile, Primate, Human} from './index'; +import { Animal } from './index'; import stampit from 'stampit'; import isStamp from 'stampit/isStamp'; -test( 'double fn', function ( test ) { - const actual = double( 5 ); - const expected = 10; - - test.equal( actual, expected, 'should double the value' ); - - test.end(); -}); - -test( 'doubleXTimes', function ( test ) { - const actual = doubleXTimes( 5, 3 ); - const expected = 40; - - test.equal( actual, expected, 'should double 5 three times' ); - - test.end(); -}); - -test( 'doubleEach', function ( test ) { - const actual = doubleEach([ 0, 1, 2 ]); - const expected = [ 0, 2, 4 ]; +test('Animal exists', function(test) { + const animal = new Animal(); - test.deepEqual( actual, expected, 'should double each in the array' ); + test.ok( animal instanceof Animal, 'should create an instance of Animal' ); test.end(); }); - -test('Animal exists', function(test) { - const animal = stampit().compose(Animal); - console.log( animal().speak('bark bark bark') ); - // console.log('4. Animalxxxx', Animal.hasCreated(animal)); - console.log('1. animal', animal); - // console.log('2. isStamp(Animal)', isStamp(Animal) ); - // console.log('3. isstamp(animal)', isStamp(animal) ); - test.ok( isStamp(Animal), 'Animal is a stamp' ); - test.ok( '?', 'animal is an instance of Animal' ); - test.end(); -}); From 33ffcc61def59131e43e3910ef5f1615fdae7f3b Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sun, 11 Dec 2016 19:15:10 -0800 Subject: [PATCH 09/12] Trying version 2 --- package.json | 2 +- src/index.js | 7 +++++++ src/spec.js | 34 +++++++++++++++++++++++++++++----- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 3af6dea..0376441 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "dependencies": { "babel-preset-es2015": "^6.13.2", "babel-preset-stage-0": "^6.5.0", - "stampit": "^3.0.6" + "stampit": "^2.0.0" }, "devDependencies": { "babel-register": "^6.14.0", diff --git a/src/index.js b/src/index.js index 824c285..3a7c238 100644 --- a/src/index.js +++ b/src/index.js @@ -2,3 +2,10 @@ import stampit from 'stampit'; // export const Animal = stampit(); + +// I don't understand why there is an object being passed in here... +const SelfAwareStamp = stampit.init(({ instance, stamp }) => { + instance.getStamp = () => stamp; +}); + +export const SelfAwareAnimal = Animal.compose(SelfAwareStamp); diff --git a/src/spec.js b/src/spec.js index 2fa2377..70cda6d 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,12 +1,36 @@ import test from 'tape'; -import { Animal } from './index'; +import { Animal, SelfAwareAnimal } from './index'; import stampit from 'stampit'; -import isStamp from 'stampit/isStamp'; +// import isStamp from 'stampit/isStamp'; -test('Animal exists', function(test) { - const animal = new Animal(); +test('Can create stamps from SelfAwareAnimal', function(test) { + const animal = SelfAwareAnimal(); - test.ok( animal instanceof Animal, 'should create an instance of Animal' ); + test.deepEqual( animal.getStamp(), SelfAwareAnimal, 'should create an "instance"/stamp from SelfAwareAnimal' ); test.end(); }); + +test('More "inheritance" stamp tests', function(test) { + let actual, expected; + + const reptile = new Reptile(); + + test.ok( reptile instanceof Reptile, 'should be an instance of Reptile' ); + test.ok( reptile instanceof Animal, 'should be an instance of Animal' ); + + expected = Reptile.SOUND; + actual = reptile.speak(); + test.equal( actual, expected, 'should make a reptile sound when it speaks' ); + + const primate = new Primate(); + + test.ok( primate instanceof Primate, 'should be an instance of Primate' ); + test.ok( primate instanceof Animal, 'should be an instance of Animal' ); + + expected = Primate.SOUND; + actual = primate.speak(); + test.equal( actual, expected, 'should make a primate sound when it speaks' ); + + test.end(); +}); \ No newline at end of file From 5cc3fbd23410fa48ac9c0a8996117bfb3d297b6d Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Sun, 11 Dec 2016 21:27:31 -0800 Subject: [PATCH 10/12] =?UTF-8?q?save=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.js | 20 ++++++++++++++------ src/spec.js | 22 ++++++++++------------ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 0376441..3af6dea 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "dependencies": { "babel-preset-es2015": "^6.13.2", "babel-preset-stage-0": "^6.5.0", - "stampit": "^2.0.0" + "stampit": "^3.0.6" }, "devDependencies": { "babel-register": "^6.14.0", diff --git a/src/index.js b/src/index.js index 3a7c238..620b7ce 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,19 @@ import stampit from 'stampit'; // +export const Animal = stampit({ + props: { + SOUND: "Generic sound" + }, + methods: { + speak(sound) { + return sound; + } + } +}); -export const Animal = stampit(); -// I don't understand why there is an object being passed in here... -const SelfAwareStamp = stampit.init(({ instance, stamp }) => { - instance.getStamp = () => stamp; -}); +export const Reptile = stampit().compose(Animal); + +export const Primate = stampit().compose(Animal); -export const SelfAwareAnimal = Animal.compose(SelfAwareStamp); +export const Human = stampit().compose(Primate); \ No newline at end of file diff --git a/src/spec.js b/src/spec.js index 70cda6d..2860a67 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,29 +1,27 @@ import test from 'tape'; -import { Animal, SelfAwareAnimal } from './index'; +import { Animal, Reptile } from './index'; import stampit from 'stampit'; // import isStamp from 'stampit/isStamp'; -test('Can create stamps from SelfAwareAnimal', function(test) { - const animal = SelfAwareAnimal(); - - test.deepEqual( animal.getStamp(), SelfAwareAnimal, 'should create an "instance"/stamp from SelfAwareAnimal' ); - +test('Can create instances from Animal stamp', function(test) { + const animal = Animal(); + test.ok( typeof animal.speak == 'function', 'animal sounds like an Animal' ); test.end(); }); test('More "inheritance" stamp tests', function(test) { let actual, expected; - const reptile = new Reptile(); + const reptile = Reptile(); - test.ok( reptile instanceof Reptile, 'should be an instance of Reptile' ); - test.ok( reptile instanceof Animal, 'should be an instance of Animal' ); + test.ok( typeof reptile.speak("I'm a reptile") == "I'm a reptile", 'should be an instance of Reptile' ); + test.ok( typeof reptile.speak == 'function', 'should be an instance of Animal' ); expected = Reptile.SOUND; - actual = reptile.speak(); + actual = reptile.speak(expected); test.equal( actual, expected, 'should make a reptile sound when it speaks' ); - const primate = new Primate(); + const primate = Primate(); test.ok( primate instanceof Primate, 'should be an instance of Primate' ); test.ok( primate instanceof Animal, 'should be an instance of Animal' ); @@ -33,4 +31,4 @@ test('More "inheritance" stamp tests', function(test) { test.equal( actual, expected, 'should make a primate sound when it speaks' ); test.end(); -}); \ No newline at end of file +}); From a1634dc9e4d7985316bdfc9b1a3686ba226035d2 Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Mon, 12 Dec 2016 18:10:51 -0800 Subject: [PATCH 11/12] Save --- src/index.js | 7 +++---- src/spec.js | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index 620b7ce..1c53f74 100644 --- a/src/index.js +++ b/src/index.js @@ -2,18 +2,17 @@ import stampit from 'stampit'; // export const Animal = stampit({ props: { - SOUND: "Generic sound" + SOUND: "generic sound" }, methods: { - speak(sound) { + speak(sound = this.SOUND) { return sound; } } }); - export const Reptile = stampit().compose(Animal); export const Primate = stampit().compose(Animal); -export const Human = stampit().compose(Primate); \ No newline at end of file +export const Human = stampit().compose(Primate); diff --git a/src/spec.js b/src/spec.js index 2860a67..5e38ea5 100644 --- a/src/spec.js +++ b/src/spec.js @@ -9,6 +9,17 @@ test('Can create instances from Animal stamp', function(test) { test.end(); }); + +test('x', function(test) { + const animal = new Animal(); + const expected = 'generic sound'; + const actual = animal.speak(); + + test.equal( actual, expected, 'should make a generic sound when it speaks' ); + test.end(); +}); + + test('More "inheritance" stamp tests', function(test) { let actual, expected; @@ -21,14 +32,14 @@ test('More "inheritance" stamp tests', function(test) { actual = reptile.speak(expected); test.equal( actual, expected, 'should make a reptile sound when it speaks' ); - const primate = Primate(); + // const primate = Primate(); - test.ok( primate instanceof Primate, 'should be an instance of Primate' ); - test.ok( primate instanceof Animal, 'should be an instance of Animal' ); + // test.ok( primate instanceof Primate, 'should be an instance of Primate' ); + // test.ok( primate instanceof Animal, 'should be an instance of Animal' ); - expected = Primate.SOUND; - actual = primate.speak(); - test.equal( actual, expected, 'should make a primate sound when it speaks' ); + // expected = Primate.SOUND; + // actual = primate.speak(); + // test.equal( actual, expected, 'should make a primate sound when it speaks' ); - test.end(); + // test.end(); }); From 482cb8109ceb44cfc3139b8cf90e31a870b90610 Mon Sep 17 00:00:00 2001 From: sheriffderek Date: Tue, 13 Dec 2016 00:29:11 -0800 Subject: [PATCH 12/12] Rethinks stamps use + tries ducktyping --- src/index.js | 8 +++---- src/spec.js | 61 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/index.js b/src/index.js index 1c53f74..5a8f70a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import stampit from 'stampit'; // export const Animal = stampit({ - props: { + properties: { SOUND: "generic sound" }, methods: { @@ -11,8 +11,8 @@ export const Animal = stampit({ } }); -export const Reptile = stampit().compose(Animal); +export const Reptile = stampit().compose(Animal).properties({SOUND: 'reptile sound'}); -export const Primate = stampit().compose(Animal); +export const Primate = stampit().compose(Animal).properties({SOUND: 'primate sound'}); -export const Human = stampit().compose(Primate); +export const Human = stampit().compose(Primate).properties({SOUND: 'human sound'}); diff --git a/src/spec.js b/src/spec.js index 5e38ea5..5b3039d 100644 --- a/src/spec.js +++ b/src/spec.js @@ -1,45 +1,62 @@ import test from 'tape'; -import { Animal, Reptile } from './index'; +import { Animal, Reptile, Primate, Human } from './index'; import stampit from 'stampit'; // import isStamp from 'stampit/isStamp'; -test('Can create instances from Animal stamp', function(test) { +test('Can create "stamps?" from Animal stamp', function(test) { + const animal = Animal(); - test.ok( typeof animal.speak == 'function', 'animal sounds like an Animal' ); - test.end(); -}); + test.ok( typeof animal.speak == 'function', 'animal has a speak function.. "looks like an Animal"' ); + + test.equal( animal.speak(), 'generic sound', 'Sounds like an Animal'); -test('x', function(test) { - const animal = new Animal(); - const expected = 'generic sound'; - const actual = animal.speak(); + console.log('* Animal says: ' + animal.speak() ); + // Must be an Animal? - test.equal( actual, expected, 'should make a generic sound when it speaks' ); test.end(); }); test('More "inheritance" stamp tests', function(test) { + let actual, expected; const reptile = Reptile(); - test.ok( typeof reptile.speak("I'm a reptile") == "I'm a reptile", 'should be an instance of Reptile' ); - test.ok( typeof reptile.speak == 'function', 'should be an instance of Animal' ); + test.ok( typeof reptile.speak == 'function', 'reptile has a speak function.. "looks like an Animal"' ); + + expected = reptile.SOUND; + actual = reptile.speak(); + console.log('* reptile says: ', actual); + test.equal( actual, expected, 'should make a reptile sound when it speaks.. "Sounds like a Reptile"' ); - expected = Reptile.SOUND; - actual = reptile.speak(expected); - test.equal( actual, expected, 'should make a reptile sound when it speaks' ); + const primate = Primate(); - // const primate = Primate(); + test.ok( typeof primate.speak == 'function', 'primate has a speak function.. "looks like an Animal"' ); - // test.ok( primate instanceof Primate, 'should be an instance of Primate' ); - // test.ok( primate instanceof Animal, 'should be an instance of Animal' ); + expected = primate.SOUND; + actual = primate.speak(); + console.log('* primate says: ', actual); + test.equal( actual, expected, 'should make a primate sound when it speaks.. Sounds like a Primate' ); - // expected = Primate.SOUND; - // actual = primate.speak(); - // test.equal( actual, expected, 'should make a primate sound when it speaks' ); + test.end(); +}); - // test.end(); + +test('Human tests...', function(test) { + + let actual, expected; + + const human = Human(); + //hmmmmm + test.ok( typeof human.speak == 'function', 'reptile has a speak function.. "looks like an Animal"' ); + + const message = 'hello'; + expected = message; + actual = human.speak( message ); + console.log('* human says: ', actual); + test.equal( actual, expected, 'should make a primate sound when it speaks.. Sounds like a Primate' ); + + test.end(); });