GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(expect): optimize checking the input type (#8840) · vitest-dev/vitest@0696898

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/browser/src/client/tester/expect
    • toHaveFormValues.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/browser/src/client/tester/expect/toHaveFormValues.ts
+9-6Lines 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 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.