Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/property-provider/src/fromStatic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { fromStatic } from "./fromStatic";

describe("fromStatic", () => {
it("should convert a static value into a provider", async () => {
const provider = fromStatic("string");

expect(await provider()).toBe("string");
const staticValue = "staticValue";
const provider = fromStatic(staticValue);
return expect(provider()).resolves.toStrictEqual(staticValue);
});

it("should always return the same promise", () => {
const provider = fromStatic("string");
const result = provider();

expect(provider()).toBe(result);
Array.from({ length: 5 }).forEach(item => {
expect(provider()).toStrictEqual(result);
});
});
});
6 changes: 2 additions & 4 deletions packages/property-provider/src/fromStatic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Provider } from "@aws-sdk/types";

export function fromStatic<T>(staticValue: T): Provider<T> {
const promisified = Promise.resolve(staticValue);
return () => promisified;
}
export const fromStatic = <T>(staticValue: T): Provider<T> => () =>
Promise.resolve(staticValue);