1+ import * as nonEmptyOrUndefinedFunction from '../utilities/nonEmptyOrUndefined' ;
12import { formatName } from '../formatName' ;
23
34describe ( '#formatName()' , ( ) => {
4- it ( 'returns an empty string when nothing is defined' , ( ) => {
5- const name = { givenName : undefined , familyName : undefined } ;
5+ it ( 'calls nonEmptyOrUndefined on givenName and familyName' , ( ) => {
6+ const nonEmptyOrUndefinedSpy = jest
7+ . spyOn ( nonEmptyOrUndefinedFunction , 'nonEmptyOrUndefined' )
8+ . mockImplementation ( jest . fn ( ) ) ;
9+
10+ formatName ( { name : { } , locale : '' } ) ;
11+
12+ expect ( nonEmptyOrUndefinedSpy ) . toHaveBeenCalledTimes ( 2 ) ;
13+
14+ nonEmptyOrUndefinedSpy . mockRestore ( ) ;
15+ } ) ;
16+
17+ it ( 'returns undefined' , ( ) => {
18+ const testCases = [ undefined , null , ' ' , '' ] ;
619 const locale = 'en-CA' ;
7- expect ( formatName ( { name, locale} ) ) . toBe ( '' ) ;
20+
21+ testCases . forEach ( ( givenName ) => {
22+ testCases . forEach ( ( familyName ) => {
23+ const name = { givenName, familyName} ;
24+ expect ( formatName ( { name, locale} ) ) . toBeUndefined ( ) ;
25+ } ) ;
26+ } ) ;
827 } ) ;
928
1029 it ( 'returns only the givenName when familyName is missing' , ( ) => {
@@ -135,7 +154,7 @@ describe('#formatName()', () => {
135154 ) . toBe ( 'last' ) ;
136155 } ) ;
137156
138- it ( 'returns a string when familyName is undefined using full' , ( ) => {
157+ it ( 'returns undefined when familyName is undefined using full' , ( ) => {
139158 const name = { givenName : '' , familyName : undefined } ;
140159 const locale = 'en-CA' ;
141160 const options = { full : true } ;
@@ -146,10 +165,10 @@ describe('#formatName()', () => {
146165 locale,
147166 options,
148167 } ) ,
149- ) . toBe ( '' ) ;
168+ ) . toBeUndefined ( ) ;
150169 } ) ;
151170
152- it ( 'returns a string when givenName and familyName are missing using full' , ( ) => {
171+ it ( 'returns undefined when givenName and familyName are missing using full' , ( ) => {
153172 const name = { givenName : undefined , familyName : undefined } ;
154173 const locale = 'en-CA' ;
155174 const options = { full : true } ;
@@ -160,7 +179,7 @@ describe('#formatName()', () => {
160179 locale,
161180 options,
162181 } ) ,
163- ) . toBe ( '' ) ;
182+ ) . toBeUndefined ( ) ;
164183 } ) ;
165184
166185 it ( 'defaults to givenName familyName for unknown locale using full' , ( ) => {
0 commit comments