本文整理汇总了TypeScript中nock.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript nock.default方法的具体用法?TypeScript nock.default怎么用?TypeScript nock.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nock
的用法示例。
在下文中一共展示了nock.default方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: testMultpart
it('should generate valid multipart upload if media and metadata are both set', 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);
});
示例2: it
it('should parse the response body into an object using \'JSON.parse\'', done => {
const requestHandler = nock('https://api.github.com')
.intercept('/path', 'method')
.reply(300, '{"foo": "bar"}');
(api as any).request('method', '/path').then((data: any) => {
expect(data).toEqual({foo: 'bar'});
done();
});
requestHandler.done();
});
示例3: it
it("resolves when request succeeds with response body", () => {
const body = "body"
nock(url)
.get("/")
.reply(200, body)
const p = request.send(HTTPMethod.GET, url)
return Promise.all([
expect(p).to.be.fulfilled,
expect(p).to.eventually.be.equal(body),
])
})
示例4: expect
it("should return subpaths from shallow get request", async () => {
nock(serverUrl)
.get("/.json")
.query({ shallow: true, limitToFirst: "1234" })
.reply(200, {
a: true,
x: true,
f: true,
});
await expect(remote.listPath("/", 1234)).to.eventually.eql(["a", "x", "f"]);
});
示例5: Error
it('should fail if file write fails', async () => {
const artifactRequest = nock(BASE_URL).get(ARTIFACT_PATH).reply(200, ARTIFACT_CONTENTS);
try {
WRITEFILE_RESULT = 'Test Error';
await retriever.downloadBuildArtifact(12345, 777, 'COMMIT', ARTIFACT_PATH);
throw new Error('Exception Expected');
} catch (error) {
expect(error.message).toEqual('CircleCI artifact download failed (Test Error)');
}
artifactRequest.done();
});
示例6: it
it('should revoke credentials if access token present', async () => {
const scope = nock('https://accounts.google.com')
.get('/o/oauth2/revoke?token=abc')
.reply(200, {success: true});
const oauth2client =
new googleapis.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
oauth2client.credentials = {access_token: 'abc', refresh_token: 'abc'};
const res = await oauth2client.revokeCredentials();
assert.equal(res.data.success, true);
assert.equal(JSON.stringify(oauth2client.credentials), '{}');
});
示例7: expect
it("writes the consumer and provider details into the pact", () => {
nock(mock.baseUrl)
.post(/pact$/, {
consumer: { name: "aconsumer" },
pactfile_write_mode: "overwrite",
provider: { name: "aprovider" },
})
.reply(200)
return expect(mock.writePact()).to.eventually.be.fulfilled
})
示例8: testInsert
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);
});