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

Update ember-window-mock, drop unused glue code #399

Merged
merged 3 commits into from
Jul 26, 2024
Merged

Conversation

simonihmig
Copy link
Contributor

@simonihmig simonihmig commented Jul 23, 2024

Copy link

changeset-bot bot commented Jul 23, 2024

🦋 Changeset detected

Latest commit: 04d1800

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
ember-browser-services Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@simonihmig simonihmig force-pushed the update-window-mock branch from 79d7051 to 5bbca34 Compare July 23, 2024 16:47
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

yay!!

@simonihmig simonihmig marked this pull request as ready for review July 23, 2024 17:05
// NOTE:
// - Location implementation is incomplete:
// https://github.com/kaliber5/ember-window-mock/blob/2b8fbf581fc65e7f5455cd291497a3fdc2efdaf5/addon-test-support/-private/mock/location.js#L23
// - does not allow setting "origin"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

// @ts-expect-error
import locationFactory from 'ember-window-mock/test-support/-private/mock/location';

const AUGMENTS: Array<string | symbol> = ['origin'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

get(target, key, receiver) {
if (key === 'location') return location;
if (key === 'parent') return self;
if (key === 'top') return self;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

},
set(target, key, value, receiver) {
if (key === 'location') {
throw new Error(`location cannot be set on window`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not correct actually. See https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Though Window.location is a read-only Location object, you can also assign a string to it. This means that you can work with location as if it were a string in most cases: location = 'http://www.example.com' is a synonym of location.href = 'http://www.example.com'.

ember-window-mock itself always allowed this behaviour, see https://github.com/simonihmig/ember-window-mock/blob/master/test-app/tests/unit/run-window-tests.ts#L123-L129

module('Stubbing location.origin', function (hooks) {
setupBrowserFakes(hooks, {
window: {
location: { origin: 'http://init.ial', href: 'http://init.ial' },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropping this test can be seen as a breaking change, see the changelog comment

@NullVoxPopuli any concerns?

Copy link
Contributor

Choose a reason for hiding this comment

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

nope, the migration path seems straight-forward!

Copy link

@ynotdraw ynotdraw left a comment

Choose a reason for hiding this comment

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

🎉

@simonihmig simonihmig merged commit 0f38686 into main Jul 26, 2024
20 checks passed
@simonihmig simonihmig deleted the update-window-mock branch July 26, 2024 09:03
@github-actions github-actions bot mentioned this pull request Jul 26, 2024
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.

4 participants