Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
@jedmao/location
Advanced tools
Readme
A LocationMock
class that extends URL
and implements the Location interface of the Web API
. As always, with first-class TypeScript support!
npm i --save-dev @jedmao/location
import { LocationMock } from '@jedmao/location'
const loc = new LocationMock('http://foo.com/')
loc.assign('http://bar.com/')
loc.replace('http://baz.com/')
loc.reload()
Because this package extends URL
, many features are provided for free. This means you can do this:
new LocationMock('http://jed:secret@test:42/foo?bar=baz#qux')
Which returns the following object:
LocationMock {
href: 'http://jed:secret@test:42/foo?bar=baz#qux',
origin: 'http://test:42',
protocol: 'http:',
username: 'jed',
password: 'secret',
host: 'test:42',
hostname: 'test',
port: '42',
pathname: '/foo',
search: '?bar=baz',
searchParams: URLSearchParams { 'bar' => 'baz' },
hash: '#qux' }
A common use for this package is to mock the window.location
, which you can do in Jest like so:
const { location: savedLocation } = window
beforeAll(() => {
delete window.location
})
beforeEach(() => {
window.location = new LocationMock('http://test/')
})
afterAll(() => {
window.location = savedLocation
})
it('assigns /login', () => {
const assign = jest
.spyOn(window.location, 'assign')
.mockImplementationOnce(() => {})
window.location.assign('/login')
expect(assign).toHaveBeenCalledWith('/login')
})
FAQs
A Location class that implements the Location interface of the Web API.
The npm package @jedmao/location receives a total of 123,445 weekly downloads. As such, @jedmao/location popularity was classified as popular.
We found that @jedmao/location demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.