Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
cypress-react-router
Advanced tools
npm install cypress-react-router
Adds cy.historyPush()
and cy.historyReplace()
commands to the Cypress object to navigate using the React Router Dom history API. Both commands take the path
and an optional state
object as parameters.
If you are wondering if you should use this package the most likely answer is no.
In most cases you should do something like:
cy.visit('/')
cy.get('[href="/article/42"]').click();
Or use some other cy.get()
selector, or even better cy.findByRole('link', { name: 'Article 42' })
from Cypress Testing Library.
So if you should not use this normally why does it exist?
In some cases you need to do setup work and the navigate to some well know route with previously setup data. So you might do something like:
cy.visit('/');
cy.login();
cy.visit('/article/42');
The problem here is that the second cy.visit()
reloads the application from the server. And if your application is a Single Page Application or SPA using React Router Dom you have just lost all state setup with the call to your custom cy.login()
command.
So instead of calling cy.visit()
a second time we want to do a history.push()
like you would in the React application and what happens if you click on a <Link />
component in the browser. And that is what this package will let you do.
In the file containing your <BrowserRouter />
or <HashRouter />
add the <CypressHistorySupport />
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { CypressHistorySupport } from 'cypress-react-router';
const App = () => {
return (
<BrowserRouter>
<CypressHistorySupport />
{/* Your other components */}
</BrowserRouter>
);
};
In /cypress/support/commands.js
add support for the router commands
import 'cypress-react-router/add-commands';
Then in your Cypress tests use the cy.historyPush()
or cy.historyReplace()
commands as needed.
context('Open secure articles', () => {
beforeEach(() => {
cy.visit('/');
cy.login();
});
it('navigates to article 42 without reload', () => {
cy.historyPush('/article/42');
// Do whatever you need to do
});
});
FAQs
Adds cy.routerNavigate() command to the Cypress object to navigate using the React Router Dom history API. The command take the to and an optional options object as parameters.
The npm package cypress-react-router receives a total of 5,728 weekly downloads. As such, cypress-react-router popularity was classified as popular.
We found that cypress-react-router 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.