fix: fetchFromMultipleSources returns errorOccurred only if all sources fail
This commit is contained in:
@@ -21,8 +21,8 @@ describe("fetchFromMultipleSources", () => {
|
||||
expect(result).toEqual(2);
|
||||
});
|
||||
|
||||
it("has promises with valid responses, contains no errors", async () => {
|
||||
const { errors } = await fetchFromMultipleSources<number>([
|
||||
it("has promises with valid responses, no error occurred", async () => {
|
||||
const { errorOccurred } = await fetchFromMultipleSources<number>([
|
||||
() => Promise.resolve(undefined),
|
||||
() => Promise.resolve(null),
|
||||
() => Promise.reject(),
|
||||
@@ -30,28 +30,25 @@ describe("fetchFromMultipleSources", () => {
|
||||
() => Promise.resolve(3),
|
||||
]);
|
||||
|
||||
expect(errors).toBeNull();
|
||||
expect(errorOccurred).toBeFalse();
|
||||
});
|
||||
|
||||
it("has promises with no valid responses, returns null", async () => {
|
||||
it("has promises that all throw, returns null", async () => {
|
||||
const { result } = await fetchFromMultipleSources<number>([
|
||||
() => Promise.resolve(null),
|
||||
() => Promise.reject("error"),
|
||||
() => Promise.resolve(undefined),
|
||||
() => Promise.reject(new Error("error")),
|
||||
]);
|
||||
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("has promises with no valid responses, contains error", async () => {
|
||||
const { errors } = await fetchFromMultipleSources<number>([
|
||||
() => Promise.resolve(null),
|
||||
it("has promises that all throw, contains error", async () => {
|
||||
const { errorOccurred } = await fetchFromMultipleSources<number>([
|
||||
() => Promise.reject("error"),
|
||||
() => Promise.reject(new Error("error")),
|
||||
() => Promise.resolve(undefined),
|
||||
]);
|
||||
|
||||
expect(errors).toEqual(["error", new Error("error")]);
|
||||
expect(errorOccurred).toBeTrue();
|
||||
});
|
||||
|
||||
it("has promises but cache has value, returns cached value", async () => {
|
||||
@@ -71,7 +68,7 @@ describe("fetchFromMultipleSources", () => {
|
||||
});
|
||||
|
||||
it("has promises but cache has value, contains no errors", async () => {
|
||||
const { errors } = await fetchFromMultipleSources<number>(
|
||||
const { errorOccurred } = await fetchFromMultipleSources<number>(
|
||||
[
|
||||
() => Promise.resolve(null),
|
||||
() => Promise.reject("error"),
|
||||
@@ -83,7 +80,7 @@ describe("fetchFromMultipleSources", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(errors).toBeNull();
|
||||
expect(errorOccurred).toBeFalse();
|
||||
});
|
||||
|
||||
it("has promises, no cached value, no valid response, should not save in cache", async () => {
|
||||
|
||||
Reference in New Issue
Block a user