
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
@drakensoftware/magicmock
Advanced tools
MagicMock is like a smart recording device for your software tests. Here's what it does in plain terms:
First Test Run
Future Test Runs
Example: If your app fetches weather data, MagicMock:
MagicMock is currently in BETA
⚠️ API may change in future versions
⚠️ Some edge cases not yet handled
⚠️ Use with caution in critical projects
npm install magic-mock --save-dev
// test.spec.ts
import { mockFunction } from 'magic-mock';
import { fetchData } from './api';
// Create mock
const mockedFetch = mockFunction(this, 'fetchData', fetchData);
test('returns valid data', async () => {
const result = await mockedFetch('https://api.example.com');
expect(result).toMatchSnapshot();
});
__magicMock__
directory📷 Created new snapshot for 'fetchData'
✨ Using snapshot for 'fetchData'
Initial Test Run
.snap
file in __magicMock__
Future Test Runs
secret()
to mask sensitive values
import { secret } from 'magic-mock';
const secureFetch = mockFunction(
this,
'authRequest',
(token: string) => secret(token, 'API_TOKEN')
);
Embed MagicMock in your library for seamless user experience:
// your-library.ts
import { mockFunction } from 'magic-mock';
export class DataService {
constructor(private fetcher: typeof fetch) {}
async getData(url: string) {
const safeFetch = mockFunction(this, 'safeFetch', this.fetcher);
return safeFetch(url);
}
}
User Benefits:
Mock third-party APIs not using MagicMock:
// tests/api.spec.ts
import { externalSDK } from 'third-party';
import { mockFunction } from 'magic-mock';
const mockedSDK = mockFunction(
this,
'thirdPartySDK',
externalSDK.initialize
);
test('handles SDK initialization', async () => {
const instance = await mockedSDK({ apiKey: 'test123' });
expect(instance.status).toBe('active');
});
import { mockClass } from 'magic-mock';
class PaymentProcessor {
async charge(amount: number) { /* ... */ }
}
const processor = mockClass(new PaymentProcessor(), 'PaymentGateway');
import { callMocked } from 'magic-mock';
test('complex test scenario', async () => {
const result = await callMocked(
complexWorkflow,
'custom-scenario-123'
);
// Custom assertions
});
Commit Snapshots
__magicMock__/
├── serviceA/
└── serviceB/
Snapshot Maintenance
Selective Mocking
// Disable for specific tests
beforeAll(() => {
process.env.DISABLE_MM = 'true';
});
Variable | Default | Description |
---|---|---|
DISABLE_MM | false | Disable all mocking behavior |
project-root/
├── __magicMock__/
│ ├── serviceA/
│ │ └── testDoSomething
│ │ ├── 0
│ │ └── 1
│ └── serviceB/
│ └── testDoAnotherThing
│ ├── 0
│ ├── 1
│ └── 2
├── src/
└── tests/
Q: How does MagicMock differ from Jest's built-in mocking?
A: Provides automatic snapshot-based mocking without manual mocking implementation.
Q: Can I use it with other test runners?
A: Currently optimized for Jest. Community plugins may enable other runners.
Q: How to handle changing API responses?
A: Delete relevant files and re-run tests to regenerate.
[](https://github.com/drakensoftware/magicmock)
Upgrade Your Jest Testing - MagicMock eliminates manual mock maintenance while ensuring test consistency. Start focusing on what matters - your test logic! 🚀
FAQs
Create your mocks automagically
The npm package @drakensoftware/magicmock receives a total of 3 weekly downloads. As such, @drakensoftware/magicmock popularity was classified as not popular.
We found that @drakensoftware/magicmock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.