Skip to content

Commit

Permalink
feat: adding a unit test for nock mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion committed Feb 1, 2025
1 parent 6622d99 commit 2267841
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
40 changes: 37 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"har-examples": "^3.1.1",
"msw": "^2.0.2",
"multer": "^1.4.5-lts.1",
"nock": "^14.0.0",
"prettier": "^3.0.3",
"temp-dir": "^3.0.0",
"tsup": "^8.0.1",
Expand Down
16 changes: 16 additions & 0 deletions test/mocking/nock.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import harExamples from 'har-examples';
import nock from 'nock';
import { describe, it, expect } from 'vitest';

import fetchHAR from '../../src/index.js';

describe('#fetchHAR mocking (nock)', () => {
it('should support mocking a request with `nock`', async () => {
nock('https://httpbin.org').get('/get').reply(429);

const res = await fetchHAR(harExamples.short);
expect(res.status).toBe(429);

nock.restore();
});
});

0 comments on commit 2267841

Please sign in to comment.