本文整理匯總了TypeScript中supertest-as-promised.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('allows for custom error formatting to elaborate', async () => {
const app = express();
app.use(urlString(), bodyParser.json());
app.use(urlString(), apolloExpress({
schema: TestSchema,
formatError(error) {
return {
message: error.message,
locations: error.locations,
stack: 'Stack trace'
};
}
}));
const response = await request(app)
.post(urlString())
.send({
query: '{thrower}',
});
expect(response.status).to.equal(200);
expect(JSON.parse(response.text)).to.deep.equal({
data: null,
errors: [ {
message: 'Throws!',
locations: [ { line: 1, column: 2 } ],
stack: 'Stack trace',
} ]
});
});
示例2: expect
it('applies additional validationRules', () => {
const expected = 'AlwaysInvalidRule was really invalid!';
const AlwaysInvalidRule = function (context) {
return {
enter() {
context.reportError(new GraphQLError(
expected
));
return BREAK;
},
};
};
app = createApp({apolloOptions: {
schema: Schema,
validationRules: [AlwaysInvalidRule],
}});
const req = request(app)
.post('/graphql')
.send({
query: 'query test{ testString }',
});
return req.then((res) => {
expect(res.status).to.equal(400);
return expect(res.body.errors[0].message).to.equal(expected);
});
});
示例3: request
it('/me Route Test', async () => {
// noinspection TypeScriptValidateTypes
await request(app)
.get('/api/user/me')
.expect(401);
});
示例4: Error
it('can reject non-whitelisted queries', () => {
const store = new OperationStore(Schema);
store.put('query testquery{ testString }');
const app = createApp({ apolloOptions: {
schema: Schema,
formatParams(params) {
if (params.query) {
throw new Error('Must not provide query, only operationName');
}
params['query'] = store.get(params.operationName);
return params;
},
}});
const expected = [{
data: {
testString: 'it works',
},
}, {
errors: [{
message: 'Must not provide query, only operationName',
}],
}];
const req = request(app)
.post('/graphql')
.send([{
operationName: 'testquery',
}, {
query: '{ testString }',
}]);
return req.then((res) => {
expect(res.status).to.equal(200);
return expect(res.body).to.deep.equal(expected);
});
});
示例5: test
it('can handle batch requests', () => {
const app = createApp();
const expected = [
{
data: {
testString: 'it works',
},
},
{
data: {
testArgument: 'hello yellow',
},
},
];
const req = request(app)
.post('/graphql')
.send([{
query: `
query test($echo: String){ testArgument(echo: $echo) }
query test2{ testString }`,
variables: { echo: 'world' },
operationName: 'test2',
},
{
query: `
query testX($echo: String){ testArgument(echo: $echo) }`,
variables: { echo: 'yellow' },
operationName: 'testX',
}]);
return req.then((res) => {
expect(res.status).to.equal(200);
return expect(res.body).to.deep.equal(expected);
});
});