11'use strict' ;
22
3- const toString = require ( './index' ) ;
3+ const makeString = require ( './index' ) ;
4+ const expect = require ( 'chai' ) . expect ;
5+ const assert = require ( 'assert' ) ;
46
5- describe ( "test make string" , ( ) => {
6- it ( "test string with single quote" , ( ) => {
7+ describe ( "test toString method" , ( ) => {
8+ it ( "test string with quotes" , ( ) => {
9+ const str = makeString ( "ajay" ) ;
10+ expect ( str ) . to . be . a ( 'string' ) ;
11+ expect ( str ) . to . equal ( JSON . stringify ( "ajay" ) ) ;
12+ } ) ;
13+
14+ it ( "test string without quotes" , ( ) => {
15+ const str = makeString ( "ajay" , { quotes : 'no' } ) ;
16+ expect ( str ) . to . be . a ( 'string' ) ;
17+ expect ( str ) . to . equal ( 'ajay' ) ;
18+ } ) ;
19+
20+ it ( "test Boolean with quotes" , ( ) => {
21+ const str = makeString ( true ) ;
22+ expect ( str ) . to . be . a ( 'string' ) ;
23+ expect ( str ) . to . equal ( JSON . stringify ( true ) ) ;
24+ } ) ;
25+
26+ it ( "test Boolean without quotes" , ( ) => {
27+ const str = makeString ( true , { quotes : 'double' } ) ;
28+ expect ( str ) . to . be . a ( 'string' ) ;
29+ expect ( str ) . to . equal ( 'true' ) ;
30+ } ) ;
31+
32+ it ( "test null value to string" , ( ) => {
33+ const str = makeString ( null ) ;
34+ expect ( str ) . to . be . a ( 'string' ) ;
35+ expect ( str ) . to . equal ( JSON . stringify ( null ) ) ;
36+ } ) ;
737
38+ it ( "test number to string" , ( ) => {
39+ const str = makeString ( 25 ) ;
40+ expect ( str ) . to . be . a ( 'string' ) ;
41+ expect ( str ) . to . equal ( JSON . stringify ( 25 ) ) ;
842 } ) ;
943
10- it ( "test string with double quote" , ( ) => {
44+ it ( "test Empty Object to string" , ( ) => {
45+ const sampleObject = { }
46+ const str = makeString ( sampleObject ) ;
47+ expect ( str ) . to . be . a ( 'string' ) ;
48+ expect ( str ) . to . equal ( JSON . stringify ( sampleObject ) ) ;
49+ } ) ;
50+
51+ it ( "test Object to string" , ( ) => {
52+ const sampleObject = {
53+ name : "Ajay" ,
54+ city : "san jose"
55+ }
56+ const str = makeString ( sampleObject ) ;
57+ expect ( str ) . to . be . a ( 'string' ) ;
58+ expect ( str ) . to . equal ( JSON . stringify ( sampleObject ) ) ;
59+ } ) ;
1160
61+ it ( "test Object with boolean to string" , ( ) => {
62+ const sampleObject = {
63+ name : "Ajay" ,
64+ city : "san jose" ,
65+ single : true
66+ }
67+ const str = makeString ( sampleObject ) ;
68+ expect ( str ) . to . be . a ( 'string' ) ;
69+ expect ( str ) . to . equal ( JSON . stringify ( sampleObject ) ) ;
1270 } ) ;
71+
72+ it ( "test Object with Date to string" , ( ) => {
73+ const sampleObject = {
74+ name : "Ajay" ,
75+ city : "san jose" ,
76+ dateOfBirth : new Date ( )
77+ }
78+ const str = makeString ( sampleObject ) ;
79+ expect ( str ) . to . be . a ( 'string' ) ;
80+ expect ( str ) . to . equal ( JSON . stringify ( sampleObject ) ) ;
81+ } ) ;
82+
83+ it ( "test Object to string without braces" , ( ) => {
84+ const sampleObject = {
85+ name : "Ajay" ,
86+ city : "san jose"
87+ }
88+ const str = makeString ( sampleObject , { braces : 'false' } ) ;
89+ expect ( str ) . to . be . a ( 'string' ) ;
90+ expect ( str ) . to . equal ( '"name":"Ajay","city":"san jose"' ) ;
91+ } ) ;
92+
93+ it ( "test Object to string without braces and different assignment" , ( ) => {
94+ const sampleObject = {
95+ name : "Ajay" ,
96+ city : "san jose"
97+ }
98+ const str = makeString ( sampleObject , { braces : 'false' , assignment : '=' } ) ;
99+ expect ( str ) . to . be . a ( 'string' ) ;
100+ expect ( str ) . to . equal ( '"name"="Ajay","city"="san jose"' ) ;
101+ } ) ;
102+
103+ it ( "test Array to string" , ( ) => {
104+ const sampleArray = [ "New York" , "San Jose" , "Charlotte" ] ;
105+ const str = makeString ( sampleArray ) ;
106+ expect ( str ) . to . be . a ( 'string' ) ;
107+ expect ( str ) . to . equal ( JSON . stringify ( sampleArray ) ) ;
108+ } ) ;
109+
110+ it ( "test Array to string without braces" , ( ) => {
111+ const sampleArray = [ "New York" , "San Jose" , "Charlotte" ] ;
112+ const str = makeString ( sampleArray , { braces : 'false' } ) ;
113+ expect ( str ) . to . be . a ( 'string' ) ;
114+ expect ( str ) . to . equal ( '"New York","San Jose","Charlotte"' ) ;
115+ } ) ;
116+
13117} ) ;
0 commit comments