diff --git a/packages/dnb-eufemia/src/extensions/forms/Field/String.tsx b/packages/dnb-eufemia/src/extensions/forms/Field/String.tsx index bf00022d403..efcf0be70d3 100644 --- a/packages/dnb-eufemia/src/extensions/forms/Field/String.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/Field/String.tsx @@ -155,6 +155,7 @@ function StringComponent(props: Props) { /> ) : mask ? ( { expect(screen.getByLabelText('The label')).toBeInTheDocument() }) + it('input is connected to label', () => { + const { rerender } = render() + + expect(document.querySelector('input').getAttribute('id')).toBe( + document.querySelector('label').getAttribute('for') + ) + + rerender() + + expect(document.querySelector('textarea').getAttribute('id')).toBe( + document.querySelector('label').getAttribute('for') + ) + + rerender() + + expect(document.querySelector('input').getAttribute('id')).toBe( + document.querySelector('label').getAttribute('for') + ) + }) + it('renders error', () => { render() expect(