Skip to content

Commit

Permalink
feat: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanshuit914 committed Mar 5, 2024
1 parent d838860 commit 3e4d0f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/hmpo-text/macro.njk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
hmpoGetOptions(ctx, params, "label")
),
hint: hmpoGetOptions(ctx, params, "hint", true),
prefix: params.prefix if hmpoGetOptions(ctx, params, "prefix", true) else "",
prefix: hmpoGetOptions(ctx, params, "prefix", true) if params.prefix else "",
value: hmpoGetValue(ctx, params),
errorMessage: hmpoGetError(ctx, params),
type: params.type,
Expand Down
14 changes: 12 additions & 2 deletions components/hmpo-text/spec.macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,23 @@ describe('hmpoText', () => {
});

it('renders with label and prefix', () => {
const $ = render({ component: 'hmpoText', params: { id: 'my-input' }, ctx: true }, locals);
const $ = render({ component: 'hmpoText', params: { id: 'my-input', prefix: '£' }, ctx: true }, locals);

const $label = $('.govuk-label');
expect($label.text().trim()).to.equal('[fields.my-input.label]');
expect($label.attr('id')).to.equal('my-input-label');
const $prefix = $('.govuk-input__prefix');
expect($prefix.text()).to.equal('£');
});

it('renders with label and without prefix', () => {
const $ = render({ component: 'hmpoText', params: { id: 'my-input', prefix: '' }, ctx: true }, locals);

const $label = $('.govuk-label');
expect($label.text().trim()).to.equal('[fields.my-input.label]');
expect($label.attr('id')).to.equal('my-input-label');
const $prefix = $('.govuk-input__prefix');
expect($prefix.text().trim()).to.equal('[fields.my-input.prefix]');
expect($prefix.text().trim()).to.equal('');
});

it('renders with value', () => {
Expand Down

0 comments on commit 3e4d0f1

Please sign in to comment.