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 snapshot tests #37

Merged
merged 9 commits into from
Dec 2, 2024
Merged

Add snapshot tests #37

merged 9 commits into from
Dec 2, 2024

Conversation

Olivia-Box-Power
Copy link
Collaborator

No description provided.

@Olivia-Box-Power Olivia-Box-Power linked an issue Nov 20, 2024 that may be closed by this pull request
Copy link
Collaborator

@alice-hannah alice-hannah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Olivia,

This looks good and seems to work ok generally.

I noted the comment at the start of the test file to say that the R session should be restarted before running any tests. I read this and still got myself in a muddle when reviewing the code! The tests depend on the prior state, but they also change the resulting state, both of which should be avoided.

I think if it was me, I'd rather use_afcharts was untested until this could be managed. I'm not sure of the best way to do this, but these might be worth thinking about:

My only other suggestion for this PR would be to make some improvements to the organisation of the tests:

  • The tidyverse style guide says that test files should be organised to match the files in R/. So here that would mean splitting out the tests in test-chart-output.R into files test-theme_af.R, test-scale_fill_discrete_af.R, etc.

  • The code defining helper functions for tests could then be moved into a helper file so they are available to all tests.

  • The code to load the test data could be moved to a setup file or alternatively could just be called as e.g. ggplot2::mpg where required.

I hope that's helpful. I'll approve the PR as everything works and it's your call whether you want to make any of these changes at this time.

Thanks!
Alice

DESCRIPTION Show resolved Hide resolved
@Olivia-Box-Power
Copy link
Collaborator Author

Olivia-Box-Power commented Dec 2, 2024

Thanks @alice-hannah.

I agree with you about it being bad practice to change the state, so I've commented out the use_afcharts test for the time being. I couldn't see any withr function that would work for this purpose, but good thinking! I think we may as well wait for ggplot2 to be updated rather than trying to reset defaults ourselves.

I hadn't seen a test helper file before, but it looks really useful. I've moved the helper functions into the file.

I forgot I could use package:: to load datasets! I've updated throughout.

I've kept all the snapshot tests in a single file for the time being, as there's not that many of them. Agree though that if the tests become longer should move into an individual file per function.

@Olivia-Box-Power Olivia-Box-Power marked this pull request as draft December 2, 2024 10:21
@Olivia-Box-Power Olivia-Box-Power marked this pull request as ready for review December 2, 2024 10:27
@Olivia-Box-Power Olivia-Box-Power merged commit d1f8160 into development Dec 2, 2024
7 checks passed
@Olivia-Box-Power Olivia-Box-Power deleted the add-tests branch December 2, 2024 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit tests
2 participants