Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
testdouble-nock
Advanced tools
Support for testdouble.js for users of Nock!
$ npm i -D testdouble-nock
Then, from a test helper, invoke the module and pass in both td
and nock
, like so:
global.td = require('testdouble')
global.nock = require('nock')
require('testdouble-nock')(td, nock)
We'll want to clear out our stubbings after each test, so add something like this to your test runner's beforeEach() hook:
beforeEach: function () {
td.reset.onNextReset(() => nock.cleanAll())
},
afterEach: function () {
td.reset() // <-- you should already be doing this!
}
For an example of a helper that sets up testdouble.js, testdouble-nock, and ensures td.reset() is called after each test, look at test/helper.js in this repo.
When you invoke testdouble-nock
, it adds a new top-level td.api()
function that allows you to mock an external API by exposing common HTTP methods as mocked methods. Here's an example:
describe('My API test', () => {
it('should return a 200 for status', (done) => {
const myApi = td.api('http://www.my-api.com')
td.when(myApi.get('/status')).thenReturn('All good here!')
request.get('http://www.my-api.com/status', (req, res, body) => {
assert.equals(body, 'All good here!')
done()
})
})
})
You can also verify that a call has taken place using td.verify
:
describe('My API test', () => {
it('should return a 200 for status', (done) => {
const myApi = td.api('http://www.my-api.com')
request.get('http://www.my-api.com/status', (req, res, body) => {
td.verify(myApi.get('/status'))
done()
})
})
})
FAQs
testdouble.js extension to add support for nock request mocking
We found that testdouble-nock 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.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.