-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mock-doc): set hostname when location is updated (#2689)
* fix(mock-doc): set hostname when location is updated The hostname was not updated when a new href is set on the window location, it looks like this was an oversight, this commit makes it so the hostname is populated like everything else. * chore(test): add test for MockLocation behaviour
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { MockWindow } from '../window'; | ||
|
||
describe('location.href', () => { | ||
let win: MockWindow; | ||
beforeEach(() => { | ||
win = new MockWindow(` | ||
<html> | ||
<head> | ||
</head> | ||
</head> | ||
`); | ||
win.location.href = "http://stencil:[email protected]:3000/path/to/page?var=var#hash" | ||
}); | ||
|
||
it('window.location.href', () => { | ||
expect(win.location.href).toBe("http://stencil:[email protected]:3000/path/to/page?var=var#hash"); | ||
}); | ||
it('window.location.protocol', () => { | ||
expect(win.location.protocol).toBe("http:"); | ||
}); | ||
it('window.location.host', () => { | ||
expect(win.location.host).toBe("stenciljs.com:3000"); | ||
}); | ||
it('window.location.hostname', () => { | ||
expect(win.location.hostname).toBe("stenciljs.com"); | ||
}); | ||
it('window.location.port', () => { | ||
expect(win.location.port).toBe("3000"); | ||
}); | ||
it('window.location.pathname', () => { | ||
expect(win.location.pathname).toBe("/path/to/page"); | ||
}); | ||
it('window.location.search', () => { | ||
expect(win.location.search).toBe("?var=var"); | ||
}); | ||
it('window.location.hash', () => { | ||
expect(win.location.hash).toBe("#hash"); | ||
}); | ||
it('window.location.username', () => { | ||
expect(win.location.username).toBe("stencil"); | ||
}); | ||
it('window.location.password', () => { | ||
expect(win.location.password).toBe("secret"); | ||
}); | ||
it('window.location.origin', () => { | ||
expect(win.location.origin).toBe("http://stenciljs.com:3000"); | ||
}); | ||
}); | ||
|
||
describe('location', () => { | ||
let win: MockWindow; | ||
beforeEach(() => { | ||
win = new MockWindow(` | ||
<html> | ||
<head> | ||
</head> | ||
</head> | ||
`); | ||
win.location = "http://stencil:[email protected]:3000/path/to/page?var=var#hash" | ||
}); | ||
|
||
it('window.location.href', () => { | ||
expect(win.location.href).toBe("http://stencil:[email protected]:3000/path/to/page?var=var#hash"); | ||
}); | ||
it('window.location.protocol', () => { | ||
expect(win.location.protocol).toBe("http:"); | ||
}); | ||
it('window.location.host', () => { | ||
expect(win.location.host).toBe("stenciljs.com:3000"); | ||
}); | ||
it('window.location.hostname', () => { | ||
expect(win.location.hostname).toBe("stenciljs.com"); | ||
}); | ||
it('window.location.port', () => { | ||
expect(win.location.port).toBe("3000"); | ||
}); | ||
it('window.location.pathname', () => { | ||
expect(win.location.pathname).toBe("/path/to/page"); | ||
}); | ||
it('window.location.search', () => { | ||
expect(win.location.search).toBe("?var=var"); | ||
}); | ||
it('window.location.hash', () => { | ||
expect(win.location.hash).toBe("#hash"); | ||
}); | ||
it('window.location.username', () => { | ||
expect(win.location.username).toBe("stencil"); | ||
}); | ||
it('window.location.password', () => { | ||
expect(win.location.password).toBe("secret"); | ||
}); | ||
it('window.location.origin', () => { | ||
expect(win.location.origin).toBe("http://stenciljs.com:3000"); | ||
}); | ||
}); |