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

Reset to doNothingHandler in tests #201

Merged

Conversation

alexlafroscia
Copy link
Contributor

When the tests are finished, rather than replacing the handler with null, it makes more sense to reset the handler back to the default handler. This can be achieved by passing nothing (aka undefined) to the setCurrentHandler function, as it'll fall back to the default value.

Our test suite is getting a bunch of instances of trying to call methods on null when trying to upgrade to 0.7.0, and I think the reset to null here is the culprit. It's pretty tough to track down which test suite is not mocking the window correctly, but I think this change would get us un-stuck!

When the tests are finished, rather than replacing the handler with
`null`, it makes more sense to reset the handler back to the default
handler. This can be achieved by passing nothing (aka `undefined`) to
the `setCurrentHandler` function, as it'll fall back to the default
value.
Copy link
Owner

@simonihmig simonihmig left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this, and sorry for the trouble here!

@rwjblue also mentioned this in #191 (comment). The other issue of handling nested usage correctly is something that we can improve a bit later, I'll publish a bugfix release with this in a minute!

@simonihmig simonihmig merged commit 4a1e8b9 into simonihmig:master Jul 15, 2020
@simonihmig simonihmig added the bug label Jul 15, 2020
@simonihmig simonihmig changed the title fix: reset to doNothingHandler Reset to doNothingHandler in tests Jul 15, 2020
@simonihmig
Copy link
Owner

Released https://github.com/kaliber5/ember-window-mock/releases/tag/v0.7.1

simonihmig added a commit that referenced this pull request Jul 23, 2020
This adds better test coverage for calls to `setupWindowMock()`, specifically the nested usage discussed with @rwjblue in #191#discussion_r454379796.

It turned out that the current implementation (after being fixed by @alexlafroscia in #201) already supports the nested case properly, as the `mockHandler` is set up in the `beforeEach` hook, so as long as there is any nested `setupWindowMock()` the window object will be mocked, and only when a test is not somehow wrapped in a setup call will it see the unmocked window.
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.

None yet

2 participants