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

chore(test, reproduction): reproduce issue about location #349

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ function createLocation(target?: Window) {
});
}

export function patchWindow(target: any) {
export function patchWindow(target: any, windowOptions: any = {}) {
let location = createLocation(target);

let self: any = new Proxy(target, {
get(target, key, receiver) {
if (key === 'location') return location;
if (key === 'parent') return self;
if (key === 'top') return self;
if (key === 'parent' && !('parent' in windowOptions)) return self;
if (key === 'top' && !('top' in windowOptions)) return self;

return Reflect.get(target, key, receiver);
},
Expand Down
Empty file removed test-app/tests/unit/.gitkeep
Empty file.
30 changes: 30 additions & 0 deletions test-app/tests/unit/services/browser/window-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ module('Service | browser/window', function (hooks) {
assert.strictEqual(service.parent.location.href, loginPath);
});
});
module('Stubbing different hrefs in location and parent.location', function (hooks) {
setupBrowserFakes(hooks, {
window: {
location: { href: 'http://iframe.window' },
parent: { location: { href: 'http://top.window' } },
},
});

test('location.href can be different from parent.location.href', function (assert) {
let service = getWindowService(this.owner);

assert.notStrictEqual(service.self, service.parent, 'self !== parent');
assert.notStrictEqual(
service.location,
service.parent.location,
'self !== parent (location)'
);
assert.strictEqual(service.location.href, 'http://iframe.window/', 'window.location.href');
assert.strictEqual(
service.parent.location.href,
'http://top.window/',
'window.parent.location.href'
);
assert.notStrictEqual(
service.location.href,
service.parent.location.href,
'hrefs are different'
);
});
});

module('Stubbing location.origin', function (hooks) {
setupBrowserFakes(hooks, {
Expand Down
2 changes: 1 addition & 1 deletion test-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// Setting `noEmitOnError` here allows ember-cli-typescript to catch errors
// and inject them into Ember CLI's build error reporting, which provides
// nice feedback for when
"noEmitOnError": true,
"noEmitOnError": false,

// We use Babel for emitting runtime code, because it's very important that
// we always and only use the same transpiler for non-stable features, in
Expand Down