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

Docs: Add html_safe example to testing->slots section #1815

Merged
merged 2 commits into from
Aug 10, 2023

Conversation

tgaff
Copy link
Contributor

@tgaff tgaff commented Aug 8, 2023

What are you trying to accomplish?

I'm trying to make a (small) testing bump in the road easy to resolve.

I ran into an issue where a tested component was rendering the passed slot as plain text. I thought a doc example with html_safe might help others with testing.

    component.tap do |c|
      c.with_buttons { "<div><button>bigger</button><a href='smaller'>smaller</a></div>" }
    end
    render_inline(component)

Results in the following page.find('.some-class').native.inner_html

<div class=\"flex justify-end gap-3 bg-secondary-50 px-6 py-3\">&lt;div&gt;&lt;button&gt;bigger&lt;/button&gt;&lt;a href='smaller'&gt;smaller&lt;/a&gt;&lt;/div&gt;</div>"

What approach did you choose and why?

It's not really worth it to do templating in tests. This seems like an easy compromise.

Anything you want to highlight for special attention from reviewers?

Nah, this is straightforward I think.

@camertron
Copy link
Contributor

Hey @tgaff, thanks for this! Could you add an entry to CHANGELOG.md please?

Ran into an issue where a tested component was rendering the passed slot as plain text.  Thought a doc example with `html_safe` might help others with testing.
@tgaff
Copy link
Contributor Author

tgaff commented Aug 10, 2023

@camertron Done.
Sorry for the commit noise here. I originally just made the change via the web-editor but ended up re-basing it to satisfy the linters.

@camertron camertron merged commit 9ec7ec5 into ViewComponent:main Aug 10, 2023
19 checks passed
@tgaff tgaff deleted the tgaff/testing_html_safe branch August 14, 2023 08:05
claudiob pushed a commit to claudiob/view_component that referenced this pull request Dec 22, 2023
…t#1815)

* Add `html_safe` example to testing doc slots section

Ran into an issue where a tested component was rendering the passed slot as plain text.  Thought a doc example with `html_safe` might help others with testing.

* Update CHANGELOG.md
claudiob pushed a commit to claudiob/view_component that referenced this pull request Jan 3, 2024
…t#1815)

* Add `html_safe` example to testing doc slots section

Ran into an issue where a tested component was rendering the passed slot as plain text.  Thought a doc example with `html_safe` might help others with testing.

* Update CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants