-
Notifications
You must be signed in to change notification settings - Fork 9
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
Is there any way to set window.location and window.parent.location to different values? #348
Comments
In I tried using the import { render } from '@ember/test-helpers';
import { maybeMake } from 'ember-browser-services/test-support';
import { hbs } from 'ember-cli-htmlbars';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
module('Integration | Helper | is-running-in-iframe', function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
let service = maybeMake(true, window);
this.owner.register('service:browser/window', service);
});
test('it returns TRUE when the app is running in an IFrame', async function (assert) {
let browserWindowMock = this.owner.lookup('service:browser/window');
browserWindowMock.location.href = 'inner';
browserWindowMock.parent.location.href = 'outer';
await render(hbs`{{if (is-running-in-iframe) "TRUE" "FALSE"}}`);
assert.dom(this.element).hasText('TRUE');
});
}); Am I on the right lines here? I also saw this: simonihmig/ember-window-mock#175, which seems to be related
|
thanks for the report! yeah, you're on the right track! -- and what you have is a valid way to test this stuff -- though, it would def be great to figure out a way make this more ergonomic (but what you haven't isn't bad or anything, it's just manual) I copied the gist of your report here: #349
the only thing I can think of is maybe opting out of that if key === parent line that you identified. like, maybe if |
@NullVoxPopuli thanks for your response. I realised that I could take a different approach here. Our {
location: 'inner',
parent: { location: 'outer' },
} This works fine for our situation. Happy to close this issue now. |
We have a helper called
is-running-in-iframe
. It compares the value ofwindow.location.href
andwindow.parent.location.href
. If these values are different, then (for our purposes) that means our Ember app is running inside an iframe.In our implementation of the helper, we use
@service('browser/window')
to help with testing. Our test looks like this (simplified here for clarity):This test worked with version
1.1.6
of ember-browser-services. After upgrading to version2.1.0
, this test started to fail.After investigating, I've tracked down the problem to this line of code:
ember-browser-services/ember-browser-services/src/test-support/window-mock-augments.ts
Line 40 in a337c0a
I understand that ember-browser-services is intentionally keeping the value of
window.location
andwindow.parent.location
in sync. I found the relevant tests. But here we have a case where we want to allow those values to diverge.Do you have any thoughts about how to support this?
The text was updated successfully, but these errors were encountered: