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

refac: refactoring setup.ts #1166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/setup/setup.ts
Expand Up @@ -18,7 +18,7 @@ import {DirectOptions} from './directApi'
/**
* Default options applied when API is called per `userEvent.anyApi()`
*/
const defaultOptionsDirect: Required<Options> = {
const defaultOptionsDirect: Config = {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to the existing defined Config.

export type Config = Required<Options>

applyAccept: true,
autoModify: true,
delay: 0,
Expand All @@ -36,7 +36,7 @@ const defaultOptionsDirect: Required<Options> = {
/**
* Default options applied when API is called per `userEvent().anyApi()`
*/
const defaultOptionsSetup: Required<Options> = {
const defaultOptionsSetup: Config = {
...defaultOptionsDirect,
writeToClipboard: true,
}
Expand All @@ -63,10 +63,10 @@ export type Config = Required<Options>

export function createConfig(
options: Options = {},
defaults: Required<Options> = defaultOptionsSetup,
defaults: Config = defaultOptionsSetup,
node?: Node,
): Config {
const document = getDocument(options, node, defaults)
const document = getDocument(options, defaults, node)

return {
...defaults,
Expand Down Expand Up @@ -168,11 +168,7 @@ export function createInstance(
}
}

function getDocument(
options: Partial<Config>,
node: Node | undefined,
defaults: Required<Options>,
) {
function getDocument(options: Options, defaults: Config, node?: Node) {
Copy link
Author

@ssi02014 ssi02014 Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createConfig and getDocument seem to take the same arguments, so I unified the order in which they take them. What do you think?

return (
options.document ?? (node && getDocumentFromNode(node)) ?? defaults.document
)
Expand Down