This repository was archived by the owner on Aug 7, 2021. It is now read-only.
File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
- const { getIndentationCharacter, writePackageJson } = require ( "./projectHelpers" ) ;
1
+ const { getIndentationCharacter, writePackageJson, safeGet } = require ( "./projectHelpers" ) ;
2
2
const fs = require ( "fs" ) ;
3
3
4
4
describe ( 'projectHelpers' , ( ) => {
@@ -57,6 +57,28 @@ describe('projectHelpers', () => {
57
57
} ) ;
58
58
} ) ;
59
59
60
+ describe ( 'safeGet' , ( ) => {
61
+ it ( 'should return the correct value of existing properties' , ( ) => {
62
+ const obj = { a : 15 } ;
63
+ expect ( safeGet ( obj , 'a' ) ) . toBe ( 15 ) ;
64
+ } ) ;
65
+
66
+ it ( 'should return undefined for unexisting properties' , ( ) => {
67
+ const obj = { a : 15 } ;
68
+ expect ( safeGet ( obj , 'random' ) ) . toBeUndefined ( ) ;
69
+ } ) ;
70
+
71
+ it ( 'should return undefined when the first argument is undefined' , ( ) => {
72
+ let obj ;
73
+ expect ( safeGet ( obj , 'random' ) ) . toBeUndefined ( ) ;
74
+ } ) ;
75
+
76
+ it ( 'should return undefined when the first argument is not an object and does not have inherited property with the queried name' , ( ) => {
77
+ const num = 15 ;
78
+ expect ( safeGet ( num , 'random' ) ) . toBeUndefined ( ) ;
79
+ } ) ;
80
+ } ) ;
81
+
60
82
describe ( 'writePackageJson' , ( ) => {
61
83
const mockFileSystemApi = ( ) => {
62
84
const data = {
You can’t perform that action at this time.
0 commit comments