diff --git a/CHANGELOG.md b/CHANGELOG.md index 420f03d711..70015db096 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ Internal: - Update pre-release step to check for new components (PR [#574](https://github.com/alphagov/govuk-frontend/pull/574)) +- Ensure render function does not have undefined object + (PR [#587](https://github.com/alphagov/govuk-frontend/pull/587)) ## 0.0.25-alpha (Breaking release) diff --git a/lib/jest-helpers.js b/lib/jest-helpers.js index e0eaf96ffd..31a44e1671 100644 --- a/lib/jest-helpers.js +++ b/lib/jest-helpers.js @@ -20,6 +20,9 @@ nunjucks.configure(configPaths.src, { * @returns {function} returns cheerio (jQuery) instance of the template for easy DOM querying */ function render (componentName, params) { + if (typeof params === 'undefined') { + throw new Error('Parameters passed to `render` should be an object but are undefined') + } const output = nunjucks.render(componentName + '/template.njk', { params }) return cheerio.load(output) } diff --git a/src/button/template.test.js b/src/button/template.test.js index 19b390402e..0a7f7915d9 100644 --- a/src/button/template.test.js +++ b/src/button/template.test.js @@ -241,7 +241,7 @@ describe('Button', () => { }) it('renders an input[type=submit] if you don\'t pass anything', () => { - const $ = render('button') + const $ = render('button', {}) const $component = $('.govuk-c-button') expect($component.get(0).tagName).toEqual('input') diff --git a/src/input/template.test.js b/src/input/template.test.js index ea2379ec75..5326919074 100644 --- a/src/input/template.test.js +++ b/src/input/template.test.js @@ -43,7 +43,7 @@ describe('Input', () => { }) it('renders with type="text" by default', () => { - const $ = render('input') + const $ = render('input', {}) const $component = $('.govuk-c-input') expect($component.attr('type')).toEqual('text')