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.
context-thief
Advanced tools
Context Thief stores the current context value for the inputted context for use in tests.
If you test components with contexts and don't want to create a new function or component every time, this module is for you!
npm install --save-dev context-thief
createContextThief(context)
Returns: {ContextThief, contextValue}
Object containing the component to render and the outputted value
Parameter | Type | Description |
---|---|---|
context | Context | Instance of React.Context to consume |
example-component.tsx
import React from "react";
export const ExampleContext = React.createContext(false);
export const ExampleComponent: React.FC<{children: React.ReactNode}> = ({children}) => {
return (
<TestContext.Provider value={true}>
{children}
</TestContext.Provider>
);
};
example-component.test.tsx
import React from "react";
import {render} from "@testing-library/react";
import {createContextThief} from "context-thief";
import {ExampleContext, ExampleComponent} from "./example-component";
it("should have the default current context value", () => {
const {ContextThief, contextValue} = createContextThief(ExampleContext);
render(
<ExampleComponent>
<ContextThief />
</ExampleComponent>
);
expect(contextValue.current).toBe(true);
});
Copyright Evelyn Hathaway, MIT License
Icon glyph made by Gregor Cresnar
FAQs
Helper function to steal React context values for testing
The npm package context-thief receives a total of 0 weekly downloads. As such, context-thief popularity was classified as not popular.
We found that context-thief 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.