Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Jul 25, 2020
1 parent e984e21 commit 32279ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/__test__/spec-helpers.js
Expand Up @@ -8,7 +8,7 @@ export const polyfillWindow = () => {
_window = global.window
global.window = Object.create(window)

Object.defineProperty(global.window, 'location', {
Object.defineProperty(window, 'location', {
value: {
href: 'https://app.biz/',
pathname: '/',
Expand All @@ -22,18 +22,18 @@ export const polyfillWindow = () => {
},
})

global.window.localStorage = memStorage()
window.localStorage = memStorage()

// this is fixed in the latest jsdom, but jest has not yet updated the jsdom dependency
window.origin = window.location.origin
Object.defineProperty(MessageEvent.prototype, 'origin', {
writable: true,
value: window.origin,
})
MessageEvent.prototype.origin = global.window.location.origin
MessageEvent.prototype.origin = window.location.origin
}

export const polyunfillWindow = () => {
delete global.window.localStorage
delete window.localStorage
global.window = _window
}
10 changes: 5 additions & 5 deletions src/__test__/storage.spec.js
Expand Up @@ -44,7 +44,7 @@ describe('ipcStorage', () => {
// eslint-disable-next-line jest/no-test-callback
it(`requests '${expectedMethod}' over window.postMessage`, async (done) => {
expect.assertions(3)
global.window.addEventListener('message', function listener(event) {
window.addEventListener('message', function listener(event) {
try {
const storageRequest = event.data['solid-auth-client']
const { id, method, args } = storageRequest
Expand All @@ -53,21 +53,21 @@ describe('ipcStorage', () => {
}
expect(method).toBe(`storage/${expectedMethod}`)
expect(args).toEqual(expectedArgs)
global.window.postMessage(
window.postMessage(
{
'solid-auth-client': {
id,
ret: expectedRet,
},
},
global.window.location.origin
window.location.origin
)
global.window.removeEventListener('message', listener)
window.removeEventListener('message', listener)
} catch (e) {
done.fail(e)
}
})
const client = new Client(global.window, global.window.location.origin)
const client = new Client(window, window.location.origin)
const store = ipcStorage(client)
const item = await store[expectedMethod](...expectedArgs)
expect(item).toBe(expectedRet)
Expand Down

0 comments on commit 32279ff

Please sign in to comment.