diff --git a/app/assets/javascripts/updateStatus.js b/app/assets/javascripts/updateStatus.js index a4a06b03b..d39e232be 100644 --- a/app/assets/javascripts/updateStatus.js +++ b/app/assets/javascripts/updateStatus.js @@ -48,7 +48,14 @@ .attr('id', id); this.$textbox - .attr('aria-described-by', this.$textbox.attr('aria-described-by') + ' ' + id) + .attr( + 'aria-described-by', + ( + this.$textbox.attr('aria-described-by') || '' + ) + ( + this.$textbox.attr('aria-described-by') ? ' ' : '' + ) + id + ) .on('input', throttle(this.update, 150)) .trigger('input'); diff --git a/tests/javascripts/updateStatus.test.js b/tests/javascripts/updateStatus.test.js index fc84a2600..a626d1fdb 100644 --- a/tests/javascripts/updateStatus.test.js +++ b/tests/javascripts/updateStatus.test.js @@ -85,6 +85,20 @@ describe('Update content', () => { }); + test("It should handle a textarea without an aria-described-by attribute", () => { + + document.getElementById('template_content').removeAttribute('aria-described-by'); + + window.GOVUK.modules.start(); + + expect( + document.getElementById('template_content').getAttribute('aria-described-by') + ).toEqual( + "update-status" + ); + + }); + test("It should make requests to the URL specified in the data-updates-url attribute", () => { window.GOVUK.modules.start();