1- import {
2- isFile ,
3- cloneDeep ,
4- hasOwnProperty ,
5- merge ,
6- isPlainObject ,
7- } from '../util'
1+ import { hasFiles , hasOwnProperty , isFile } from '../util'
82
93describe ( 'Object Test' , ( ) => {
104 // const { window, File } = global
@@ -16,61 +10,23 @@ describe('Object Test', () => {
1610 const file = new File ( [ 'hello world!' ] , 'myfile' )
1711 expect ( isFile ( file ) ) . toBeTruthy ( )
1812 } )
19- /*
13+ it ( 'should check has own property' , function ( ) {
14+ expect ( hasOwnProperty ( { dev : null } , '' ) ) . toBeFalsy ( )
15+ } )
2016 it ( 'check if window is undefined' , ( ) => {
17+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18+ // @ts -ignore
2119 delete global . window
2220 const file = new File ( [ 'hello world!' ] , 'myfile' )
23- expect(isFile(file)).toBeFalsy()
21+ const form = new FormData ( )
22+ form . append ( 'file' , file )
23+ expect ( hasFiles ( form ) ) . toBeFalsy ( )
2424 } )
25+ /*
2526 it('check if File is not function', () => {
2627 const file = new File(['hello world!'], 'myfile')
2728 delete global.File
2829 expect(isFile(file)).toBeFalsy()
2930 })
3031 */
3132} )
32- describe ( 'cloneDeep' , ( ) => {
33- it ( 'Object is null' , ( ) => {
34- expect ( cloneDeep ( null ) ) . toBe ( null )
35- } )
36- it ( 'Object is typeof File' , ( ) => {
37- const file = new File ( [ 'hello world!' ] , 'myfile' )
38- expect ( cloneDeep ( file ) ) . toBeInstanceOf ( File )
39- } )
40- it ( 'Object is typeof Array' , ( ) => {
41- const obj = [ { name : 'Chantouch' } ]
42- expect ( cloneDeep ( obj ) ) . toBeInstanceOf ( Object )
43- } )
44- it ( 'Has own property undefined' , ( ) => {
45- const obj = [ { name : 'Chantouch' } ]
46- expect ( hasOwnProperty ( obj , undefined ) ) . toBeFalsy ( )
47- } )
48- it ( 'Merge object into object' , ( ) => {
49- const obj1 = { name : 'Chantouch' }
50- const obj2 = { email :
'[email protected] ' } 51- const merged = { email :
'[email protected] ' , name :
'Chantouch' } 52- expect ( merge ( obj1 , obj2 ) ) . toEqual ( merged )
53- } )
54- it ( 'should return `true` if the object is created by the `Object` constructor.' , ( ) => {
55- expect ( isPlainObject ( Object . create ( { } ) ) ) . toBeTruthy ( )
56- expect ( isPlainObject ( Object . create ( Object . prototype ) ) ) . toBeTruthy ( )
57- expect ( isPlainObject ( { foo : 'bar' } ) ) . toBeTruthy ( )
58- expect ( isPlainObject ( { } ) ) . toBeTruthy ( )
59- expect ( isPlainObject ( Object . create ( null ) ) ) . toBeTruthy ( )
60- } )
61- it ( 'should return `false` if the object is not created by the `Object` constructor.' , ( ) => {
62- function Foo ( this : any ) {
63- this . abc = { }
64- }
65- expect ( isPlainObject ( / f o o / ) ) . toBeFalsy ( )
66- // eslint-disable-next-line @typescript-eslint/no-empty-function
67- expect ( isPlainObject ( function ( ) { } ) ) . toBeFalsy ( )
68- expect ( isPlainObject ( 1 ) ) . toBeFalsy ( )
69- expect ( isPlainObject ( [ 'foo' , 'bar' ] ) ) . toBeFalsy ( )
70- expect ( isPlainObject ( [ ] ) ) . toBeFalsy ( )
71- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
72- // @ts -ignore
73- expect ( isPlainObject ( new Foo ( ) ) ) . toBeFalsy ( )
74- expect ( isPlainObject ( null ) ) . toBeFalsy ( )
75- } )
76- } )
0 commit comments