Add initApp test, fragment helper, page object #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The initApp() test uses the jsdom environment provided by Vitest:
The fragment() test helper works as-is in both the jsdom and browser environments. The StringCalculatorPage object follows the Page Object pattern from the Selenium WebDriver docs, even though we're not using Selenium here:
I settled on this after days of trying to figure out how to execute JS Modules on a JSDOM instance directly. See:
I finally realized that if what I wanted to do was so difficult, maybe there was a better way. So this change keeps the PageLoader-based test from before, to make sure initApp executes on DOMContentLoaded. But for the new initApp test, as for the upcoming tests for other modules, using the jsdom environment will suffice.
I was also pleased to discover that
vitest --browser
will do the right thing and not load the jsdom environment in the browser. So tests using the jsdom environment will already execute in the browser for free. (Perhaps there are features which would require a workaround between the jsdom and browser environments, but I haven't encountered them yet.)