1+ /* globals describe, it */
2+ var Person = require ( '../tasks/task-1' ) ( ) ;
3+ var expect = require ( 'chai' ) . expect ;
4+
5+ describe ( 'Tests for Classical Inheritance in JavaScript' , function ( ) {
6+ describe ( '"Task 1"' , function ( ) {
7+ var CONSTS = {
8+ VALID : {
9+ FIRSTNAME : 'Firsttest' ,
10+ LASTNAME : 'Lasttest' ,
11+ FULLNAME : 'full test' ,
12+ AGE : 5
13+ } ,
14+ INVALID : {
15+ FIRSTNAME : {
16+ SHORT : 'Ff' ,
17+ LONG : 'F' + ( new Array ( 21 ) . join ( 'f' ) )
18+ } ,
19+ LASTNAME : {
20+ SHORT : 'Ll' ,
21+ LONG : 'L' + ( new Array ( 21 ) . join ( 'l' ) )
22+ } ,
23+ AGE : {
24+ SMALLER : - 1 ,
25+ LARGER : 151
26+ }
27+ }
28+ } ;
29+
30+ it ( 'expect Person function constructor to exist' , function ( ) {
31+ expect ( Person ) . to . exist ;
32+ } ) ;
33+
34+ it ( 'expect Person to be a function' , function ( ) {
35+ expect ( Person ) . to . be . a ( 'function' ) ;
36+ } ) ;
37+
38+ it ( 'expect new Person object with valid firstname, lastname and age to set them' , function ( ) {
39+ var p = new Person ( CONSTS . VALID . FIRSTNAME , CONSTS . VALID . LASTNAME , CONSTS . VALID . AGE ) ;
40+ expect ( p . firstname ) . to . equal ( CONSTS . VALID . FIRSTNAME ) ;
41+ expect ( p . lastname ) . to . equal ( CONSTS . VALID . LASTNAME ) ;
42+ expect ( p . age ) . to . equal ( CONSTS . VALID . AGE ) ;
43+ } ) ;
44+
45+ it ( 'expect new Person object with valid firstname, lastname to set them have fullname' , function ( ) {
46+ var p = new Person ( CONSTS . VALID . FIRSTNAME , CONSTS . VALID . LASTNAME , CONSTS . VALID . AGE ) ;
47+ expect ( p . firstname ) . to . equal ( CONSTS . VALID . FIRSTNAME ) ;
48+ expect ( p . lastname ) . to . equal ( CONSTS . VALID . LASTNAME ) ;
49+ expect ( p . fullname ) . to . equal ( CONSTS . VALID . FIRSTNAME + ' ' + CONSTS . VALID . LASTNAME ) ;
50+ } ) ;
51+
52+ it ( 'expect new Person with short fistname to throw error' , function ( ) {
53+ function fn ( ) {
54+ new Person ( CONSTS . INVALID . FIRSTNAME . SHORT ,
55+ CONSTS . VALID . LASTNAME ,
56+ CONSTS . VALID . AGE ) ;
57+ }
58+ expect ( fn ) . to . throw ( ) ;
59+ } ) ;
60+ it ( 'expect new Person with long fistname to throw error' , function ( ) {
61+ function fn ( ) {
62+ new Person ( CONSTS . INVALID . FIRSTNAME . LONG , CONSTS . VALID . LASTNAME , CONSTS . VALID . AGE ) ;
63+ }
64+ expect ( fn ) . to . throw ( ) ;
65+ } ) ;
66+
67+ it ( 'expect new Person with short lastname to throw error' , function ( ) {
68+ function fn ( ) {
69+ new Person ( CONSTS . VALID . FIRSTNAME , CONSTS . INVALID . LASTNAME . SHORT , CONSTS . VALID . AGE ) ;
70+ }
71+ expect ( fn ) . to . throw ( ) ;
72+ } ) ;
73+ it ( 'expect new Person with long lastname to throw error' , function ( ) {
74+ function fn ( ) {
75+ new Person ( CONSTS . VALID . FIRSTNAME , CONSTS . INVALID . LASTNAME . LONG , CONSTS . VALID . AGE ) ;
76+ }
77+ expect ( fn ) . to . throw ( ) ;
78+ } ) ;
79+
80+
81+ it ( 'expect new Person with age ' + CONSTS . INVALID . AGE . SMALLER + ' to throw error' , function ( ) {
82+ function fn ( ) {
83+ new Person ( CONSTS . VALID . FIRSTNAME , CONSTS . VALID . LASTNAME , CONSTS . INVALID . AGE . SMALLER ) ;
84+ }
85+ expect ( fn ) . to . throw ( ) ;
86+ } ) ;
87+ it ( 'expect new Person with age ' + CONSTS . INVALID . AGE . LARGER + ' to throw error' , function ( ) {
88+ function fn ( ) {
89+ new Person ( CONSTS . VALID . FIRSTNAME , CONSTS . VALID . LASTNAME , CONSTS . INVALID . AGE . LARGER ) ;
90+ }
91+ expect ( fn ) . to . throw ( ) ;
92+ } ) ;
93+
94+ it ( 'expect person, with valid firstname, lastname and age, to return correct introduce' , function ( ) {
95+ var expected = 'Hello! My name is ' + CONSTS . VALID . FIRSTNAME + ' ' + CONSTS . VALID . LASTNAME +
96+ ' and I am ' + CONSTS . VALID . AGE + '-years-old' ;
97+
98+ var actual = ( new Person ( CONSTS . VALID . FIRSTNAME , CONSTS . VALID . LASTNAME , CONSTS . VALID . AGE ) )
99+ . introduce ( ) ;
100+ expect ( actual ) . to . equal ( expected ) ;
101+ } ) ;
102+
103+ it ( 'expect introduce to be attached to prototype' , function ( ) {
104+ expect ( Person . prototype ) . to . has . property ( 'introduce' ) ;
105+ } ) ;
106+
107+ it ( 'expect introduce to be attached to prototype' , function ( ) {
108+ expect ( Person . prototype ) . to . has . property ( 'introduce' ) ;
109+ } ) ;
110+ } ) ;
111+ } ) ;
0 commit comments