Skip to content

Commit 0696898

Browse files
authored
perf(expect): optimize checking the input type (#8840)
1 parent 9b75ec5 commit 0696898

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/browser/src/client/tester/expect/toHaveFormValues.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ export default function toHaveFormValues(
6666
// Returns the combined value of several elements that have the same name
6767
// e.g. radio buttons or groups of checkboxes
6868
function getMultiElementValue(elements: HTMLInputElement[]) {
69-
const types = [...new Set(elements.map(element => element.type))]
70-
if (types.length !== 1) {
71-
throw new Error(
72-
'Multiple form elements with the same name must be of the same type',
73-
)
69+
let type = ''
70+
for (const element of elements) {
71+
if (type && type !== element.type) {
72+
throw new Error(
73+
'Multiple form elements with the same name must be of the same type',
74+
)
75+
}
76+
type = element.type
7477
}
75-
switch (types[0]) {
78+
switch (type) {
7679
case 'radio': {
7780
const selected = elements.find(radio => radio.checked)
7881
return selected ? selected.value : undefined

0 commit comments

Comments
 (0)