-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6befe89
commit e7574ce
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
import { executeFn } from "./execute-fn"; | ||
import { Interrupt } from "./util"; | ||
|
||
describe("executeFn", () => { | ||
it("should run a function with arguments", async () => { | ||
const fn = (val: { [key: string]: string }) => Promise.resolve(val.foo); | ||
const result = await fn({ foo: "bar" }); | ||
const result = await executeFn(fn, [{foo: "bar"}] as any); | ||
expect(result).toBe("bar"); | ||
}); | ||
|
||
it("should extract interrupt from resolution", async () => { | ||
const fn = (_: string) => Promise.resolve(Interrupt.approval()); | ||
const result = await executeFn(fn, [{}] as any); | ||
expect(result).toEqual({ | ||
content: { type: "approval" }, | ||
type: "interrupt", | ||
functionExecutionTime: expect.any(Number), | ||
}); | ||
}); | ||
|
||
it("should extract interrupt from rejection", async () => { | ||
const fn = () => Promise.reject(Interrupt.approval()); | ||
const result = await executeFn(fn, [{}] as any); | ||
expect(result).toEqual({ | ||
content: { type: "approval" }, | ||
type: "interrupt", | ||
functionExecutionTime: expect.any(Number), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters