Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("set should support iterall / iterable ", () => {
const a = set([1, 2])
function leech(iter) {
const values = []
let v
do {
v = iter.next()
if (!v.done) values.push(v.value)
} while (!v.done)
return values
}
expect(iterall.isIterable(a)).toBe(true)
expect(leech(iterall.getIterator(a))).toEqual([1, 2])
expect(leech(a.entries())).toEqual([[1, 1], [2, 2]])
expect(leech(a.keys())).toEqual([1, 2])
expect(leech(a.values())).toEqual([1, 2])
})
test("array should support iterall / iterable ", () => {
var a = observable([1, 2, 3])
expect(iterall.isIterable(a)).toBe(true)
expect(iterall.isArrayLike(a)).toBe(true)
var values = []
iterall.forEach(a, v => values.push(v))
expect(values).toEqual([1, 2, 3])
var iter = iterall.getIterator(a)
expect(iter.next()).toEqual({ value: 1, done: false })
expect(iter.next()).toEqual({ value: 2, done: false })
expect(iter.next()).toEqual({ value: 3, done: false })
expect(iter.next()).toEqual({ value: undefined, done: true })
a.replace([])
iter = iterall.getIterator(a)
expect(iter.next()).toEqual({ value: undefined, done: true })
})
test("map should support iterall / iterable ", () => {
const a = mobx.observable.map({ a: 1, b: 2 })
function leech(iter) {
const values = []
let v
do {
v = iter.next()
if (!v.done) values.push(v.value)
} while (!v.done)
return values
}
expect(iterall.isIterable(a)).toBe(true)
expect(leech(iterall.getIterator(a))).toEqual([["a", 1], ["b", 2]])
expect(leech(a.entries())).toEqual([["a", 1], ["b", 2]])
expect(leech(a.keys())).toEqual(["a", "b"])
expect(leech(a.values())).toEqual([1, 2])
})
expect(iterall.isIterable(a)).toBe(true)
expect(iterall.isArrayLike(a)).toBe(true)
var values = []
iterall.forEach(a, v => values.push(v))
expect(values).toEqual([1, 2, 3])
var iter = iterall.getIterator(a)
expect(iter.next()).toEqual({ value: 1, done: false })
expect(iter.next()).toEqual({ value: 2, done: false })
expect(iter.next()).toEqual({ value: 3, done: false })
expect(iter.next()).toEqual({ value: undefined, done: true })
a.replace([])
iter = iterall.getIterator(a)
expect(iter.next()).toEqual({ value: undefined, done: true })
})