本文整理汇总了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);
});
});