Skip to content

Commit

Permalink
Merge pull request #587 from alphagov/ensure-render-function-does-not…
Browse files Browse the repository at this point in the history
…-have-undefined-object

Ensure render function does not have undefined object
  • Loading branch information
NickColley authored Mar 8, 2018
2 parents c5b273f + af0c9a2 commit 06312a6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions lib/jest-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/button/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/input/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 06312a6

Please sign in to comment.