axax
Version:
A library of async iterator extensions for JavaScript including ```map```, ```reduce```, ```filter```, ```flatMap```, ```pipe``` and [more](https://github.com/jamiemccrindle/axax/blob/master/docs/API.md#functions).
68 lines (67 loc) • 1.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const from_1 = require("../from");
const of_1 = require("../of");
const pluck_1 = require("../pluck");
const toArray_1 = require("../toArray");
test("pluck", async () => {
const source = {
a: "plucked",
x: 1,
y: 2,
z: {},
};
const result = await toArray_1.toArray(pluck_1.pluck("a")(of_1.of(source)));
expect(result).toEqual(["plucked"]);
});
test("pluck with multiple items", async () => {
const source = [
{
a: "item1",
x: 1,
},
{
a: "item2",
x: 1,
}
];
const result = await toArray_1.toArray(pluck_1.pluck("a")(from_1.from(source)));
expect(result).toEqual(["item1", "item2"]);
});
test("pluck with nested properties", async () => {
const source = {
a: {
b: 1
},
x: 2,
};
const result = await toArray_1.toArray(pluck_1.pluck("a", "b")(of_1.of(source)));
expect(result).toEqual([1]);
});
test("pluck with undefined properties", async () => {
const source = {
a: {
b: 2
},
b: 3,
x: 4,
};
const result = await toArray_1.toArray(pluck_1.pluck("a", "b", "c")(of_1.of(source)));
expect(result).toEqual([undefined]);
});
test("pluck with no parameters", async () => {
const source = {
a: 1,
};
const result = await toArray_1.toArray(pluck_1.pluck()(of_1.of(source)));
expect(result).toEqual([source]);
});
test("pluck with non-object sources", async () => {
const source = [
1,
2,
4,
];
const result = await toArray_1.toArray(pluck_1.pluck("test")(of_1.of(source)));
expect(result).toEqual([undefined]);
});