
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@jest-decorated/react
Advanced tools
Extension of @jest-decorated package.
Utilities for testing react
components. Compatible with enzyme
, @testing-libray/react
and react-dom/test-utils
.
Make sure to register ReactTestRunner
on your parent test.
Jest test:
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import MyComponent from "../MyComponent";
describe("MyComponentTest", () => {
let container = null;
beforeEach(() => {
container = document.createElement("span");
document.body.appendChild(container);
});
afterEach(() => {
unmountComponentAtNode(container);
container.remove();
container = null;
});
const renderWithProps = (props = {}) => {
act(() => {
render(<MyComponent {...props} />, container);
});
};
it("turned on by default", () => {
renderWithProps();
const button = document.querySelector("[data-testid=toggle]");
expect(button.innerHTML).toBe("Turn on");
});
it("changes value when clicked, calls onChange", () => {
const passedProps = { onChange: jest.fn() };
renderWithProps(passedProps);
const button = document.querySelector("[data-testid=toggle]");
button.dispatchEvent(new MouseEvent("click", { bubbles: true }));
expect(passedProps.onChange).toHaveBeenCalledTimes(1);
expect(button.innerHTML).toBe("Turn off");
});
});
Same test with @jest-decorated
:
import { render } from "react-dom/test-utils";
@Describe()
@RunWith(ReactTestRunner)
class MyComponentTest {
@ComponentContainer()
container;
@Act()
@ComponentProvider("../MyComponent")
provider(MyComponent, passedProps) {
return render(<MyComponent {...passedProps} />, this.container);
}
@It("turned on by default")
isTurnOn(component, { props }) {
const button = document.querySelector("[data-testid=toggle]");
expect(button.innerHTML).toBe("Turn on");
}
@It("changes value when clicked, calls onChange")
@WithProps({ onChange: jest.fn() })
shouldToggle(component, { props }) {
const button = document.querySelector("[data-testid=toggle]");
button.dispatchEvent(new MouseEvent("click", { bubbles: true }));
expect(props.onChange).toHaveBeenCalledTimes(1);
expect(button.innerHTML).toBe("Turn off");
}
}
Read here.
Contribution guidelines for this project
FAQs
Decorators for writing jest-based tests for react components.
The npm package @jest-decorated/react receives a total of 4 weekly downloads. As such, @jest-decorated/react popularity was classified as not popular.
We found that @jest-decorated/react 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
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.