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

Support for Svelte Actions? #1

Open
gossi opened this issue Aug 15, 2024 · 5 comments
Open

Support for Svelte Actions? #1

gossi opened this issue Aug 15, 2024 · 5 comments

Comments

@gossi
Copy link

gossi commented Aug 15, 2024

I was about implementing a svelte action to make my universal lib available in svelte. Implementing the action would be straight forward. Then I thought how would I test this? Coming from ember where the testing is broadly covered, I felt lost in svelte land. I test my universal lib in vitest with browser mode already and would love to continue using that for svelte, too.

So I come across this fresh project here which is only a week old, but probably exactly what I am looking for.

I see you can already test svelte component, seems the best to start with. I was wondering if you plan on providing a way to test html + an action?

PS. Also asking this for its sister project vitest-browser-vue (where in vue, this would be a directive).

@sheremet-va
Copy link
Member

By "actions" do you mean SvelteKit actions?

@gossi
Copy link
Author

gossi commented Sep 26, 2024

I was referring to svelte actions (sorry my bad, I didn't left a link).

@sheremet-va
Copy link
Member

The testing library approach promotes testing the use case instead of the implementation, so I don't think it's a good idea to provide an API to bypass that. You should create a component that uses the action and test the user behaviour.

@gossi
Copy link
Author

gossi commented Oct 9, 2024

Actually, it is meant with html in the first place. It may be wrapped in a component.

Wrapping it in a component is what I consider a hacky workaround (or as people say handing me the hammer because the problem has been turned into a nail). Coming from ember where things are considered more distinctively, I notice this as missing.

To vizualize what I mean, here is a testing code I would want to write (in pseudo-ish code):

import { page } from '@vitest/browser/context'
import { listbox } from 'aria-voyager-svelte'

test('listbox does work', async () => {
  // arrange
  const screen = page.render(
    <template>
      <div role="listbox" use:listbox>
        <span role="option">Ananas</span>
        <span role="option">Banana</span>
        <span role="option">Pear</span>
      </div>
    </template>
  )

  // act

  // assert

  // cleanup

  screen.cleanup()
})

@sheremet-va
Copy link
Member

Actually, it is meant with html in the first place. It may be wrapped in a component.

I don't see how this is a workaround. It is meant to be part of HTML in the Svelte component since it requires Svelte to function. It might even require a svelte extension to be processed correctly.

I think adding any workarounds might break the intended behaviour, so I would oppose adding support for this

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

No branches or pull requests

2 participants