Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure render function does not have undefined object #587

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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