FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
locize-cli/test/removeUndefinedFromArrays.test.js at main · locize/locize-cli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
locize
/
locize-cli
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
23
Star
72
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
locize-cli
/
test
/
removeUndefinedFromArrays.test.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (43 loc) · 2.1 KB
Breadcrumbs
locize-cli
/
test
/
removeUndefinedFromArrays.test.js
Copy path
File metadata and controls
49 lines (43 loc) · 2.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import
{
describe
,
it
,
expect
}
from
'vitest'
import
removeUndefinedFromArrays
from
'../src/removeUndefinedFromArrays.js'
// This module does not use fetch or filesystem, but we test realistic scenarios
describe
(
'removeUndefinedFromArrays'
,
(
)
=>
{
it
(
'removes leading undefined from arrays in object properties'
,
(
)
=>
{
const
obj
=
{
arr
:
[
undefined
,
'a'
,
'b'
]
,
nested
:
{
arr2
:
[
undefined
,
1
,
2
]
}
}
const
result
=
removeUndefinedFromArrays
(
JSON
.
parse
(
JSON
.
stringify
(
obj
)
)
)
expect
(
result
.
arr
)
.
toEqual
(
[
null
,
'a'
,
'b'
]
)
expect
(
result
.
nested
.
arr2
)
.
toEqual
(
[
null
,
1
,
2
]
)
}
)
it
(
'does not remove non-leading undefined or non-array properties'
,
(
)
=>
{
const
obj
=
{
arr
:
[
'a'
,
undefined
,
'b'
]
,
notArr
:
'x'
,
nested
:
{
arr2
:
[
1
,
undefined
,
2
]
}
}
const
result
=
removeUndefinedFromArrays
(
JSON
.
parse
(
JSON
.
stringify
(
obj
)
)
)
expect
(
result
.
arr
)
.
toEqual
(
[
'a'
,
null
,
'b'
]
)
expect
(
result
.
nested
.
arr2
)
.
toEqual
(
[
1
,
null
,
2
]
)
expect
(
result
.
notArr
)
.
toBe
(
'x'
)
}
)
it
(
'returns the same object if nothing to remove'
,
(
)
=>
{
const
obj
=
{
arr
:
[
'a'
,
'b'
]
,
nested
:
{
arr2
:
[
1
,
2
]
}
}
const
result
=
removeUndefinedFromArrays
(
JSON
.
parse
(
JSON
.
stringify
(
obj
)
)
)
expect
(
result
)
.
toEqual
(
obj
)
}
)
it
(
'handles null and undefined input gracefully'
,
(
)
=>
{
expect
(
removeUndefinedFromArrays
(
null
)
)
.
toBe
(
null
)
expect
(
removeUndefinedFromArrays
(
undefined
)
)
.
toBe
(
undefined
)
}
)
it
(
'removes undefined from the start of arrays'
,
(
)
=>
{
const
obj
=
{
arr
:
[
undefined
,
1
,
2
]
,
nested
:
{
arr
:
[
undefined
,
3
,
4
]
}
}
const
cleaned
=
removeUndefinedFromArrays
(
obj
)
expect
(
cleaned
.
arr
)
.
toEqual
(
[
1
,
2
]
)
expect
(
cleaned
.
nested
.
arr
)
.
toEqual
(
[
3
,
4
]
)
}
)
it
(
'does not change arrays without leading undefined'
,
(
)
=>
{
const
obj
=
{
arr
:
[
1
,
2
]
,
nested
:
{
arr
:
[
3
,
4
]
}
}
const
cleaned
=
removeUndefinedFromArrays
(
obj
)
expect
(
cleaned
.
arr
)
.
toEqual
(
[
1
,
2
]
)
expect
(
cleaned
.
nested
.
arr
)
.
toEqual
(
[
3
,
4
]
)
}
)
it
(
'returns the same object if input is falsy'
,
(
)
=>
{
expect
(
removeUndefinedFromArrays
(
null
)
)
.
toBe
(
null
)
expect
(
removeUndefinedFromArrays
(
undefined
)
)
.
toBe
(
undefined
)
}
)
}
)
Back
|
FazBrowse Home
|
New Git URL