/** * External dependencies */ import { render } from '@testing-library/react'; /** * Internal dependencies */ import { staticFormDataToObject } from '../static-form-helper'; describe( 'staticFormDataToObject', () => { it( 'should create object of all nested input, select, textarea fields within form element', () => { render(
); type FormElements = { testform?: HTMLFormElement; } & HTMLCollectionOf< HTMLFormElement >; const forms: FormElements = document.forms; let formObject; if ( forms.testform ) { formObject = staticFormDataToObject( forms.testform ); } expect( formObject ).toEqual( { Name: 'John', Car: 'audi', Description: 'Tall', } ); } ); it( 'should add array of items for select multiple', () => { render( ); type FormElements = { testform?: HTMLFormElement; } & HTMLCollectionOf< HTMLFormElement >; const forms: FormElements = document.forms; let formObject; if ( forms.testform ) { formObject = staticFormDataToObject( forms.testform ); } expect( formObject ).toEqual( { Car: [ 'volvo', 'audi' ], } ); } ); it( 'should skip input types of type button, image, and submit', () => { render( ); type FormElements = { testform?: HTMLFormElement; } & HTMLCollectionOf< HTMLFormElement >; const forms: FormElements = document.forms; let formObject; if ( forms.testform ) { formObject = staticFormDataToObject( forms.testform ); } expect( formObject ).toEqual( { Name: 'John', } ); } ); } );