本文整理汇总了TypeScript中nock类的典型用法代码示例。如果您正苦于以下问题:TypeScript nock类的具体用法?TypeScript nock怎么用?TypeScript nock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了nock类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should fail if the artifact is too large', async () => {
const artifactRequest = nock(BASE_URL).get(ARTIFACT_PATH).reply(200, ARTIFACT_CONTENTS);
retriever = new BuildRetriever(api, 10, DOWNLOAD_DIR);
try {
await retriever.downloadBuildArtifact(12345, 777, 'COMMIT', ARTIFACT_PATH);
throw new Error('Exception Expected');
} catch (error) {
expect(error.status).toEqual(413);
}
artifactRequest.done();
});
示例2: it
it("should add required Vary headers to the response", async () => {
nock(cloudRunApiOrigin)
.get("/v1alpha1/projects/project-foo/locations/us-central1/services/helloworld")
.reply(200, { status: { address: { hostname: cloudRunServiceOrigin } } });
nock(cloudRunServiceOrigin)
.get("/vary")
.reply(200, "live vary version", { vary: "Other, Authorization" });
const mwGenerator = await cloudRunProxy(fakeOptions);
const mw = await mwGenerator(fakeRewrite);
const spyMw = sinon.spy(mw);
return supertest(spyMw)
.get("/vary")
.expect(200, "live vary version")
.then((res) => {
expect(spyMw.calledOnce).to.be.true;
expect(res.header.vary).to.equal("Other, Authorization, Accept-Encoding, Cookie");
});
});
示例3: it
it('should return a single response object for single requests', async () => {
nock(Utils.baseUrl, {allowUnmocked: true})
.post('/urlshortener/v1/url')
.times(2)
.replyWithFile(
200,
path.join(
__dirname, '../../test/fixtures/urlshort-insert-res.json'));
await testInsert(localUrlshortener);
await testInsert(remoteUrlshortener);
});
示例4: it
it('should allow overriding validateStatus', async () => {
const scope = nock(Utils.baseUrl).get('/drive/v2/files').reply(500);
const google = new GoogleApis();
const drive = google.drive('v2');
const res = await drive.files.list({}, {
validateStatus: (status: number) => {
return true;
}
});
assert.equal(res.status, 500);
});
示例5: it
it('should upload a video', async () => {
const scope =
nock(Utils.baseUrl)
.post(
`/upload/youtube/v3/videos?part=id%2Csnippet%2Cstatus¬ifySubscribers=false&uploadType=multipart`)
.reply(200, {kind: 'youtube#video'});
const data = await samples.upload.runSample(someFile);
assert(data);
assert.strictEqual(data.kind, 'youtube#video');
scope.done();
});
示例6: function
util.setupExpectedWSTrustRequestCommon = function () {
var RSTRDoc = fs.readFileSync(parameters.RSTRFile, 'utf8');
var wstrustRequest = nock(parameters.adfsUrlNoPath)
.filteringRequestBody(function () { return '*'; })
.post(parameters.adfsWsTrustPath, '*')
.reply(200, RSTRDoc);
util.matchStandardRequestHeaders(wstrustRequest);
return wstrustRequest;
};
示例7: it
it('sould call callback with value', done => {
const endpoint = 'tag/sunset';
nock('https://api.instagram.com')
.get(`/v1/${endpoint}`)
.query({ access_token: 'toto' })
.reply(200, { message: 'success' });
(instagram as any).request('GET', endpoint, (_, result) => {
expect(result).toMatchSnapshot();
done();
});
});
示例8: async
async () => {
nock(Utils.baseUrl)
.post('/upload/drive/v2/files?uploadType=multipart')
.times(2)
.reply(201, (uri: string, reqBody: {}) => {
return reqBody; // return request body as response
// for testing purposes
});
await testMultpart(localDrive);
await testMultpart(remoteDrive);
});
示例9: it
it('should set loading status as expected', function () {
const scope = nock(BASE_URL).get('/api/settings').reply(200);
const promise = store.load()
.then(() => {
scope.done();
expect(store.loading).to.be.false;
});
expect(store.loading).to.be.true;
return promise;
});