mirror of https://github.com/01-edu/public.git
feat(for-each): improve test
- add check for returned value(s)
This commit is contained in:
parent
92294da2ab
commit
029fcd4a02
|
@ -1,7 +1,7 @@
|
|||
Array.prototype.forEach = undefined
|
||||
// /*/ // ⚡
|
||||
export const tests = []
|
||||
const t = (f) => tests.push(f)
|
||||
const t = f => tests.push(f)
|
||||
|
||||
export const setup = () => {
|
||||
const arr = [1, 2, 3, 4, 5, Math.random(), 7, 10, -10, 20, -95]
|
||||
|
@ -12,22 +12,25 @@ export const setup = () => {
|
|||
t(({ eq, ctx }) => {
|
||||
// callback is call with the item value
|
||||
const result = []
|
||||
forEach(ctx.arr, (value) => result.push(value))
|
||||
return eq(result, ctx.arr)
|
||||
const returned = forEach(ctx.arr, value => result.push(value))
|
||||
return eq([returned, result], [undefined, ctx.arr])
|
||||
})
|
||||
|
||||
t(({ eq, ctx }) => {
|
||||
// callback second parameter is the index
|
||||
const result = []
|
||||
forEach(ctx.arr, (_, index) => result.push(index))
|
||||
return eq(result, [...ctx.arr.keys()])
|
||||
const returned = forEach(ctx.arr, (_, index) => result.push(index))
|
||||
return eq([returned, result], [undefined, [...ctx.arr.keys()]])
|
||||
})
|
||||
|
||||
t(({ eq, ctx }) => {
|
||||
// callback third parameter is the array
|
||||
const result = []
|
||||
forEach(ctx.arr, (_, __, arr) => result.push(arr))
|
||||
return eq(result, Array(ctx.arr.length).fill(ctx.arr))
|
||||
const returned = forEach(ctx.arr, (_, __, arr) => result.push(arr))
|
||||
return eq(
|
||||
[returned, result],
|
||||
[undefined, Array(ctx.arr.length).fill(ctx.arr)],
|
||||
)
|
||||
})
|
||||
|
||||
Object.freeze(tests)
|
||||
|
|
Loading…
Reference in New Issue