Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating hooks label type to provide hint to built-in values #913

Merged
merged 1 commit into from
Aug 23, 2020
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type Hook = (...args: any[]) => void | Promise<void>;
type HookLabel = 'start' | 'end' | string;
type HookUnregister = {
unregister: () => void;
};
Expand Down Expand Up @@ -26,7 +27,7 @@ function getHelperKey(helperName: string, label: string) {
* @returns {HookUnregister} An object containing an unregister function that will unregister
* the specific hook registered to the helper.
*/
export function registerHook(helperName: string, label: string, hook: Hook): HookUnregister {
export function registerHook(helperName: string, label: HookLabel, hook: Hook): HookUnregister {
let helperKey = getHelperKey(helperName, label);
let hooksForHelper = registeredHooks.get(helperKey);

Expand Down Expand Up @@ -54,7 +55,7 @@ export function registerHook(helperName: string, label: string, hook: Hook): Hoo
* @param {any[]} args Any arguments originally passed to the test helper.
* @returns {Promise<void>} A promise representing the serial invocation of the hooks.
*/
export function runHooks(helperName: string, label: string, ...args: any[]): Promise<void> {
export function runHooks(helperName: string, label: HookLabel, ...args: any[]): Promise<void> {
let hooks = registeredHooks.get(getHelperKey(helperName, label)) || new Set<Hook>();
let promises = [...hooks].map(hook => hook(...args));

Expand Down