
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Shallowly: Modern shallow renderer for React 18+. Enzyme-compatible API, 2x faster, with TypeScript support.
"Shallowly exists for one purpose: fast, isolated unit tests of YOUR React components."
"Don't test React or third-party libraries - only test the code YOU wrote here."
Shallowly's core mantra
"Good tests don't check how React works - they check how YOUR application works with React."
✅ DO test:
❌ DON'T test:
The modern Enzyme alternative for fast unit testing with:
.textWithProps()
Enzyme is deprecated, and React Testing Library doesn't support shallow rendering. Shallowly solves this with:
npm install shallowly
# or
yarn add shallowly
Test modern features without workarounds:
shallow(
<Suspense fallback={<Loader />}>
<AsyncComponent />
</Suspense>,
);
- import { shallow } from 'enzyme';
+ import { shallow } from 'shallowly'; // Same API!
console.log(wrapper.textWithProps());
// Outputs:
// <DataFetching isLoading={true}>
// <Spinner />
// </DataFetching>
const wrapper = shallow<Props>(<User id={123} />);
wrapper.prop("id"); // Type-safe: number
npm install shallowly --save-dev
import { shallow } from "shallowly";
import vi from "vitest";
const MyComponent = ({ name, age, onClick }) => (
<div className="container">
<h1>Hello {name}</h1>
<p>You are {age} years old</p>
<button onClick={onClick}>Click me</button>
</div>
);
describe('🐛 MyComponent', () => {
it('🧪 default', () => {
expect.hasAssertions();
//☣️ Arrange (всякие моки)
const onClickSpy = vi.fn();
//🔥 Act
const wrapper = shallow(
<MyComponent name="John" age={30} onClick={onClickSpy} />,
);
//❓ Assert
expect(wrapper.text()).toMatchSnapshot();
});
it('🧪 button prop onClick', () => {
expect.hasAssertions();
//☣️ Arrange (всякие моки)
const onClickSpy = vi.fn();
//🔥 Act
const wrapper = shallow(
<MyComponent name="John" age={30} onClick={onClickSpy} />,
);
//❓ Assert
expect(wrapper.find('button').prop('onClick')).toBe(onClickSpy);
});
});
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`🐛 MyComponent > 🧪 default 1`] = `
"<div>
<h1>
Hello
John
</h1>
<p>
You are
30
years old
</p>
<button>
Click me
</button>
</div>"
`;
Operation | Shallowly 🚀 | Enzyme | React Testing Library |
---|---|---|---|
Basic component | 12ms ⚡ | 🔚💀 It is no longer supported or operational. | 85ms (7.1x slower) |
100 components | 650ms ⚡ | 🔚💀 It is no longer supported or operational. | 4500ms (6.9x slower) |
Hook-heavy component | 18ms ⚡ | 🔚💀 It is no longer supported or operational. | 210ms |
Tree traversal | 8ms ⚡ | 🔚💀 It is no longer supported or operational. | 150ms |
Key takeaways:
pie
title Test Distribution
"Unit (Shallowly)" : 70
"Integration" : 20
"E2E" : 10
📚 English Documentation | 🇷🇺 Документация на русском | 🐞 Report Issues
"Saved us 300+ lines of test boilerplate!" - @bad4iz
FAQs
Shallowly: Modern shallow renderer for React 18+. Enzyme-compatible API, 2x faster, with TypeScript support.
We found that shallowly demonstrated a healthy version release cadence and project activity because the last version was released less than 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
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.