@@ -38,20 +38,52 @@ describe('fake', () => {
38
38
39
39
it ( 'does not allow invalid module name' , ( ) => {
40
40
expect ( ( ) => faker . fake ( '{{foo.bar}}' ) ) . toThrowError (
41
- new FakerError ( 'Invalid module: foo' )
41
+ new FakerError ( `Invalid module method or definition: foo.bar
42
+ - faker.foo.bar is not a function
43
+ - faker.definitions.foo.bar is not an array` )
44
+ ) ;
45
+ } ) ;
46
+
47
+ it ( 'does not allow missing method name' , ( ) => {
48
+ expect ( ( ) => faker . fake ( '{{address}}' ) ) . toThrowError (
49
+ new FakerError ( `Invalid module method or definition: address
50
+ - faker.address is not a function
51
+ - faker.definitions.address is not an array` )
42
52
) ;
43
53
} ) ;
44
54
45
55
it ( 'does not allow invalid method name' , ( ) => {
46
56
expect ( ( ) => faker . fake ( '{{address.foo}}' ) ) . toThrowError (
47
- new FakerError ( 'Invalid method: address.foo' )
57
+ new FakerError ( `Invalid module method or definition: address.foo
58
+ - faker.address.foo is not a function
59
+ - faker.definitions.address.foo is not an array` )
60
+ ) ;
61
+ } ) ;
62
+
63
+ it ( 'does not allow invalid definitions data' , ( ) => {
64
+ expect ( ( ) => faker . fake ( '{{finance.credit_card}}' ) ) . toThrowError (
65
+ new FakerError ( `Invalid module method or definition: finance.credit_card
66
+ - faker.finance.credit_card is not a function
67
+ - faker.definitions.finance.credit_card is not an array` )
48
68
) ;
49
69
} ) ;
50
70
51
71
it ( 'should be able to return empty strings' , ( ) => {
52
72
expect ( faker . fake ( '{{helpers.repeatString}}' ) ) . toBe ( '' ) ;
53
73
} ) ;
54
74
75
+ it ( 'should be able to return locale definition strings' , ( ) => {
76
+ expect ( faker . definitions . cell_phone . formats ) . toContain (
77
+ faker . fake ( '{{cell_phone.formats}}' )
78
+ ) ;
79
+ } ) ;
80
+
81
+ it ( 'should be able to return locale definition strings that starts with the name of an existing module' , ( ) => {
82
+ expect ( faker . definitions . address . city_name ) . toContain (
83
+ faker . fake ( '{{address.city_name}}' )
84
+ ) ;
85
+ } ) ;
86
+
55
87
it ( 'should be able to handle only {{ brackets' , ( ) => {
56
88
expect ( faker . fake ( '{{hello' ) ) . toBe ( '{{hello' ) ;
57
89
expect ( faker . fake ( 'hello{{' ) ) . toBe ( 'hello{{' ) ;
0 commit comments