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 initApp test, fragment helper, page object #42

Merged
merged 1 commit into from
Dec 15, 2023
Merged

Conversation

mbland
Copy link
Owner

@mbland mbland commented Dec 15, 2023

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.)

The initApp() test uses the jsdom environment provided by Vitest:

- https://vitest.dev/guide/environment.html

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:

- https://www.selenium.dev/documentation/test_practices/design_strategies/

---

I settled on this after days of trying to figure out how to execute JS
Modules on a JSDOM instance directly. See:

- commit 86ac76f
- commit 9c87cbf
- commit d55f78d

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.)
@mbland mbland self-assigned this Dec 15, 2023
@mbland mbland merged commit 31591d9 into main Dec 15, 2023
3 checks passed
@mbland mbland deleted the use-jsdom-environment branch December 15, 2023 18:51
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.

None yet

1 participant