File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 11export const isDate = d => d instanceof Date ;
22export const isEmpty = o => Object . keys ( o ) . length === 0 ;
33export const isObject = o => o != null && typeof o === 'object' ;
4+ export const properObject = o => isObject ( o ) && ! o . hasOwnProperty ? { ...o } : o ;
Original file line number Diff line number Diff line change 11import forEach from 'jest-each' ;
22
3- import { isDate , isEmpty , isObject } from './' ;
3+ import { isDate , isEmpty , isObject , properObject } from './' ;
44
55describe ( 'utils' , ( ) => {
66
@@ -72,4 +72,27 @@ describe('utils', () => {
7272 expect ( isObject ( value ) ) . toBe ( false ) ;
7373 } ) ;
7474 } ) ;
75+
76+ describe ( '.properObject' , ( ) => {
77+ it ( 'returns given object when object has keys and hasOwnProperty function' , ( ) => {
78+ const o = { a : 1 } ;
79+ const a = [ 1 ] ;
80+ expect ( properObject ( o ) ) . toBe ( o ) ;
81+ expect ( properObject ( a ) ) . toBe ( a ) ;
82+ } ) ;
83+
84+ it ( 'returns given value when value is not an object' , ( ) => {
85+ const o = 'hello' ;
86+ expect ( properObject ( o ) ) . toBe ( o ) ;
87+ } ) ;
88+
89+ it ( 'returns object that has given keys and hasOwnProperty function when given object is created from a null' , ( ) => {
90+ const o = Object . create ( null ) ;
91+ o . a = 1 ;
92+ const actual = properObject ( o ) ;
93+ expect ( actual ) . toEqual ( { a : 1 } ) ;
94+ expect ( typeof actual . hasOwnProperty === 'function' ) . toBe ( true ) ;
95+ expect ( actual ) . not . toBe ( o ) ;
96+ } ) ;
97+ } ) ;
7598} ) ;
You can’t perform that action at this time.
0 commit comments