|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var chai = require("chai"), |
| 4 | + expect = chai.expect, |
| 5 | + cocktail = require('../../../../lib/cocktail'), |
| 6 | + // Requires = require('../../../../lib/processor/annotation/Requires.js'), |
| 7 | + Talents = require('../../../../lib/processor/annotation/Talents.js'); |
| 8 | + |
| 9 | +describe('Annotation Processor @talents', function(){ |
| 10 | + var sut = new Talents(); |
| 11 | + |
| 12 | + it('has retain set false', function(){ |
| 13 | + expect(sut.retain).to.equal(false); |
| 14 | + }); |
| 15 | + |
| 16 | + it('has priority set to cocktail.SEQUENCE.TRAITS', function(){ |
| 17 | + expect(sut.priority).to.equal(cocktail.SEQUENCE.TRAITS); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('Parameter for @talents annotation', function(){ |
| 21 | + |
| 22 | + it('accepts an array of Talents as parameter', function(){ |
| 23 | + var sut = new Talents(), |
| 24 | + traitDef = {}; |
| 25 | + |
| 26 | + sut.setParameter([traitDef]); |
| 27 | + |
| 28 | + expect(sut.getParameter()).to.contain(traitDef); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('Talents process', function(){ |
| 33 | + |
| 34 | + describe('Passing a Talent reference `@talents:[TalentA]`', function(){ |
| 35 | + var sut = new Talents(), |
| 36 | + TalentA = function(){}, |
| 37 | + myObj = {}, |
| 38 | + aMethod = function method(){}; |
| 39 | + |
| 40 | + TalentA.prototype.aMethod = aMethod; |
| 41 | + myObj.foo = 1; |
| 42 | + |
| 43 | + sut.setParameter([TalentA]); |
| 44 | + |
| 45 | + sut.process(myObj); |
| 46 | + |
| 47 | + it('makes the TalentA methods part of the given myObj', function(){ |
| 48 | + expect(myObj).to.respondTo('aMethod'); |
| 49 | + expect(myObj.aMethod).to.be.equal(aMethod); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + |
| 54 | + describe('Passing a Talent using options object `@talents: [{talent: TalentA}]`', function(){ |
| 55 | + var sut = new Talents(), |
| 56 | + TalentA = function(){}, |
| 57 | + myObj = {}, |
| 58 | + aMethod = function method(){}; |
| 59 | + |
| 60 | + TalentA.prototype.aMethod = aMethod; |
| 61 | + myObj.foo = 1; |
| 62 | + |
| 63 | + sut.setParameter([{talent: TalentA}]); |
| 64 | + |
| 65 | + sut.process(myObj); |
| 66 | + |
| 67 | + it('makes the TalentA methods part of the given myObj', function(){ |
| 68 | + expect(myObj).to.respondTo('aMethod'); |
| 69 | + expect(myObj.aMethod).to.be.equal(aMethod); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + describe('Passing a Talent reference `@talents:[TalentA]` to a Class', function(){ |
| 74 | + var sut = new Talents(), |
| 75 | + TalentA = function(){}, |
| 76 | + MyClass = function(){}, |
| 77 | + aMethod = function method(){}; |
| 78 | + |
| 79 | + TalentA.prototype.aMethod = aMethod; |
| 80 | + MyClass.prototype.foo = 1; |
| 81 | + |
| 82 | + sut.setParameter([TalentA]); |
| 83 | + |
| 84 | + sut.process(MyClass); |
| 85 | + |
| 86 | + it('makes the TalentA methods part of the given MyClass as static method', function(){ |
| 87 | + expect(MyClass).to.not.respondTo('aMethod'); |
| 88 | + expect(MyClass.aMethod).to.be.equal(aMethod); |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + }); |
| 93 | +}); |
0 commit comments