Closed NickColley closed 6 years ago
tricky, as the easiest options (putting an error on the page, or writing an error to the console) are end-user facing. End users (the public) can't do anything about invalid usage of our macros, so we really should avoid them getting errors if possible.
This has worked really well for GOV.UK Publishing Components.
It's much better to have loud warnings that can be picked up before deploying as part of tests and monitoring than to have silent failures that are picked up by end-users.
Example test: https://github.com/alphagov/govuk_publishing_components/blob/master/spec/components/radio_test_spec.rb#L12
good point. I can't see what the code in that link is doing? Does it write a big red message to the page or something?
@joelanman that test is making sure when a component doesn't get the right input it fails.
In Ruby land you can raise an exception, but Nunjucks has no such equivalent so (as far as I know).
At least in the Ruby ERB templates, they will raise an exception if something is not passed through by default. We have an empty object passed through to our templates that may mask a default behaviour if Nunjucks has it, would be worth investigating that.
Closing this as this isn't something Nunjucks supports which makes this very difficult to do. It could be a good thing to look into in the next firebreak.
Ideally our components would loudly complain if they're supplied with bad inputs.
This currently isn't trivial with our current Nunjucks setup.
Related comment: https://github.com/alphagov/govuk-frontend/issues/558#issuecomment-369239872
See this skipped test: https://github.com/alphagov/govuk-frontend/blob/master/src/back-link/template.test.js#L17