Skip to content

Commit 03f20e1

Browse files
committed
fix: apply review suggestions
1 parent 9942434 commit 03f20e1

File tree

8 files changed

+15
-25
lines changed

8 files changed

+15
-25
lines changed

src/config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {Config, ConfigFn} from '../types/config'
2-
import {Callback} from '../types/utils'
32
import {prettyDOM} from './pretty-dom'
43

5-
interface InternalConfig {
4+
type Callback<T> = () => T
5+
interface InternalConfig extends Config {
66
_disableExpensiveErrorDiagnostics: boolean
77
}
88

99
// It would be cleaner for this to live inside './queries', but
1010
// other parts of the code assume that all exports from
1111
// './queries' are query functions.
12-
let config: Config & InternalConfig = {
12+
let config: InternalConfig = {
1313
testIdAttribute: 'data-testid',
1414
asyncUtilTimeout: 1000,
1515
// this is to support React's async `act` function.

src/label-helpers.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {isNotNull} from './utils'
21
import {TEXT_NODE} from './helpers'
32

43
const labelledNodeNames = [
@@ -25,21 +24,20 @@ function getTextContent(
2524
.join('')
2625
}
2726

28-
function getLabelContent(node: Node | Element | HTMLInputElement) {
27+
function getLabelContent(element: Element | HTMLInputElement) {
2928
let textContent
30-
if ('tagName' in node && node.tagName.toLowerCase() === 'label') {
31-
textContent = getTextContent(node)
32-
} else if ('value' in node) {
33-
textContent = node.value
29+
if (element.tagName.toLowerCase() === 'label') {
30+
textContent = getTextContent(element)
31+
} else if ('value' in element) {
32+
return element.value
3433
} else {
35-
textContent = node.textContent
34+
textContent = element.textContent
3635
}
3736
return textContent
3837
}
3938

4039
// Based on https://github.com/eps1lon/dom-accessibility-api/pull/352
4140
function getRealLabels(element: Element | HTMLInputElement) {
42-
// for old browsers
4341
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
4442
if ('labels' in element && element.labels !== undefined)
4543
return element.labels ?? []
@@ -64,7 +62,7 @@ function getLabels(
6462
{selector = '*'} = {},
6563
) {
6664
const ariaLabelledBy = element.getAttribute('aria-labelledby')
67-
const labelsId = isNotNull(ariaLabelledBy) ? ariaLabelledBy.split(' ') : []
65+
const labelsId = ariaLabelledBy ? ariaLabelledBy.split(' ') : []
6866
return labelsId.length
6967
? labelsId.map(labelId => {
7068
const labellingElement = container.querySelector(`[id="${labelId}"]`)

src/matches.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
NormalizerOptions,
55
DefaultNormalizerOptions,
66
} from '../types'
7-
import {Nullish} from '../types/utils'
7+
8+
type Nullish<T> = T | null | undefined
89

910
function assertNotNullOrUndefined<T>(
1011
matcher: T,

src/utils.ts

-3
This file was deleted.

tests/jest.config.dom.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const baseConfig = require('kcd-scripts/jest')
33

44
module.exports = {
55
...baseConfig,
6-
moduleFileExtensions: [...baseConfig.moduleFileExtensions, 'd.ts'],
7-
moduleDirectories: [...baseConfig.moduleDirectories, 'types'],
86
rootDir: path.join(__dirname, '..'),
97
displayName: 'dom',
108
coveragePathIgnorePatterns: [

tests/jest.config.node.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const baseConfig = require('kcd-scripts/jest')
33

44
module.exports = {
55
...baseConfig,
6-
moduleFileExtensions: [...baseConfig.moduleFileExtensions, 'd.ts'],
7-
moduleDirectories: [...baseConfig.moduleDirectories, 'types'],
86
rootDir: path.join(__dirname, '..'),
97
displayName: 'node',
108
testEnvironment: 'jest-environment-node',

types/matches.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ARIARole} from 'aria-query'
2-
import {Nullish} from './utils'
2+
3+
type Nullish<T> = T | null | undefined
34

45
export type MatcherFunction = (
56
content: string,
@@ -13,7 +14,7 @@ export type ByRoleMatcher = ARIARole | MatcherFunction | {}
1314

1415
export type NormalizerFn = (text: string) => string
1516

16-
export type NormalizerOptions = DefaultNormalizerOptions & {
17+
export interface NormalizerOptions extends DefaultNormalizerOptions {
1718
normalizer?: NormalizerFn
1819
}
1920

types/utils.d.ts

-3
This file was deleted.

0 commit comments

Comments
 (0)