{"id":18783964,"url":"https://github.com/sparkpost/nock-inspector","last_synced_at":"2025-12-20T21:30:20.118Z","repository":{"id":33911256,"uuid":"144324249","full_name":"SparkPost/nock-inspector","owner":"SparkPost","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-27T22:11:22.000Z","size":971,"stargazers_count":0,"open_issues_count":17,"forks_count":0,"subscribers_count":32,"default_branch":"master","last_synced_at":"2024-12-29T11:49:20.962Z","etag":null,"topics":["sp-utils"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SparkPost.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-10T19:20:53.000Z","updated_at":"2020-02-20T18:18:19.000Z","dependencies_parsed_at":"2024-11-07T20:44:02.115Z","dependency_job_id":"20efb200-f01c-4d81-85ea-9109702c7d92","html_url":"https://github.com/SparkPost/nock-inspector","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SparkPost%2Fnock-inspector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SparkPost%2Fnock-inspector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SparkPost%2Fnock-inspector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SparkPost%2Fnock-inspector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SparkPost","download_url":"https://codeload.github.com/SparkPost/nock-inspector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239699583,"owners_count":19682575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sp-utils"],"created_at":"2024-11-07T20:41:28.465Z","updated_at":"2025-12-20T21:30:14.735Z","avatar_url":"https://github.com/SparkPost.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Nock Inspector\n--------------\n\nThis is a wrapper designed to make using nock easier.\n\ncreate a new nock inspector:\n```\nnockInspector = require('@sparkpost/nock-inspector');\n\nmyInspector = nockInspector({\n    method: 'POST'\n    basePath: 'https://app.sparkpost.com',\n    endpoint: '/an/endpoint',\n    //this is the default response - it is optional\n    response: {\n        //status will default to 200 if none is provided\n        status: 200,\n        //headers and body are optional\n        headers: {\n            pig: 'oink',\n        },\n        body: {\n            cow: 'moo'\n        }\n    }\n});\n```\nThis will respond with the default response to all POST requests made to https://app.sparkpost.com/an/endpoint.\n\nSpecific replies can also be tailored to specific requests, like so.\n```\nspecialRequest = {\n    //either a body or headers object is needed for the request.\n    headers: { horse: 'neigh' },\n    body: { chicken: 'woof woof'}\n};\n\nspecialResponse = {\n    //status is required\n    status: 400,\n    //headers and body are optional\n    headers: { human: 'yodeleedoo' }\n    body: { error: 'the chicken says cluck cluck, not woof woof' }\n};\n\nmyInspector.respondToRequest(specialRequest, specialResponse);\n\n```\n\nA nock inspector can respond with a specific response on the nth request to it:\n```\n// responds with the provided response on the second request\nmyInspector.respondOnCall(2, {\n    status: 403,\n    body: { error: 'no snakes allowed.' }\n});\n```\n\n##### Accessing the requests made to the mock\n\n`myInspector.request` is the most recent request intercepted by the mock. Its properties are `headers`, `body`, and `query`.\n\n`myInspector.requests` is an array of requests, each with `headers`, `body`, and `query`. `myInspector.requests[0]` is the first request intercepted by the mock.\n\n##### Listing and cleaning mocks\n```\nnockInspector = require('@sparkpost/nock-inspector');\n\n//list all active mocks\nnockInspector.activeMocks();\n\n//remove all mocks\nnockInspector.cleanAll();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparkpost%2Fnock-inspector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsparkpost%2Fnock-inspector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparkpost%2Fnock-inspector/lists"}