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

Add session$click() to testServer() #3764

Closed
daattali opened this issue Jan 6, 2023 · 4 comments
Closed

Add session$click() to testServer() #3764

daattali opened this issue Jan 6, 2023 · 4 comments

Comments

@daattali
Copy link
Contributor

daattali commented Jan 6, 2023

Currently, it's very awkward to test action buttons using testServer(), because there is no dedicated function to clicking on them. They are treated as regular inputs, so if I want to simulate a click, I need to manually set its input value to the right integer with session$setInputs().

It would be very useful to have a session$click() that would work for buttons

@daattali
Copy link
Contributor Author

daattali commented Jan 6, 2023

I just noticed the related issue #2745

@Shelmith-Kariuki
Copy link

Shelmith-Kariuki commented Jun 27, 2023

Hi @daattali ,

Thank you for opening this issue.

If I have shiny::actionButton(ns("go_button"), "Go") in my UI and shiny::observeEvent(input$go_button, {"some code goes here"}), how do I simulate a button click while running tests? session$setInputs(go_button = 1) doesn't work for me.

@Shelmith-Kariuki
Copy link

I am building an app with many observeEvents and I need a way to simulate button clicks while running tests. adding session$click() to testServer() would really come in handy.

@gadenbuie
Copy link
Member

Thanks @Shelmith-Kariuki for writing in this issue and to @daattali for opening it. I wrote an answer in the related issue here with an example of how I'd approach this problem. Shel – please let me know if you're still having issues testing your module with that approach.

I'm going to close this issue since #2745 provides a complete description of the problem. I will say that I think that it's unlikely that we'd add a specific $click() helper function. testServer() and Shiny modules are advanced enough that it's reasonable to expect users to have to understand how action buttons operate. If I'm missing a detail that makes it trickier to work with, please let me know.

@gadenbuie gadenbuie closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
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

3 participants