本文整理汇总了TypeScript中ava.TestContext类的典型用法代码示例。如果您正苦于以下问题:TypeScript TestContext类的具体用法?TypeScript TestContext怎么用?TypeScript TestContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestContext类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: inspectPushRecordCreationRequest
async function inspectPushRecordCreationRequest(t: TestContext, requestStub: SinonStub) {
// For player#create device record is already serialized. Checking serialized structure.
const anyValues = [
"device_type",
"language",
"timezone",
"device_os",
"sdk",
"delivery_platform",
"browser_name",
"browser_version",
"operating_system",
"operating_system_version",
"device_platform",
"device_model",
"identifier",
"notification_types"
];
t.is(requestStub.callCount, 1);
t.not(requestStub.getCall(0), null);
const data: any = requestStub.getCall(0).args[1];
anyValues.forEach((valueKey) => {
t.not(data[valueKey], undefined, `player create: ${valueKey} is undefined! => data: ${JSON.stringify(data)}`);
});
}
示例2: isDeprecated
return function isDeprecated(t: TestContext) {
// replace original implementation
console.warn = originalWarn
// test for correct log message, if in development
if (process.env.NODE_ENV === "development") {
t.true(spyWarn.called)
t.regex(spyWarn.getCall(0).args[0], /Deprecation warning:/)
}
}
示例3: async
fn: async (t: TestContext) => {
const ted = await Tyr.byName.user.findOne({ query: { name: 'ted' } });
if (!ted) {
throw new Error(`No ted found`);
}
const query = `
query getUserById($id: [ID]) {
user(_id: $id) {
status {
name
}
}
}
`;
const result = await Tyr.graphql({
query,
variables: {
id: [ted.$id]
}
});
const expected = {
data: {
user: {
status: {
name: 'Active'
}
}
}
};
t.deepEqual<ExecutionResult>(result, expected);
}
示例4: asyncFn
export async function expectAsyncToThrow<R>(
t: TestContext,
asyncFn: () => Promise<R>,
expectedMessageRegex: RegExp,
description = ''
) {
let threw = false;
let message = '';
try {
await asyncFn();
} catch (err) {
threw = true;
message = err.message;
}
t.true(threw, description);
t.regex(message, expectedMessageRegex, description);
}
示例5: async
fn: async (t: TestContext) => {
const query = `
query userNameQuery {
users {
name
teamIds {
name,
organizationId {
name
}
}
}
}
`;
const result = await Tyr.graphql({ query });
const expected = {
data: {
users: [
{
name: 'ben',
teamIds: [
{
name: 'burritoMakers',
organizationId: {
name: 'Chipotle'
}
},
{
name: 'chipotleMarketing',
organizationId: {
name: 'Chipotle'
}
}
]
},
{
name: 'ted',
teamIds: [
{
name: 'cavaEngineers',
organizationId: {
name: 'Cava'
}
}
]
},
{
name: 'noTeams',
teamIds: []
}
]
}
};
t.deepEqual<ExecutionResult>(result, expected);
}
示例6: async
fn: async (t: TestContext) => {
const burritoMakers = await Tyr.byName.team.findOne({
query: { name: 'burritoMakers' }
});
if (!burritoMakers) {
throw new Error(`No burrito`);
}
const query = `
query userNameQuery {
users {
name
teamIds(_id: "${burritoMakers.$id}") {
name,
organizationId {
name
}
}
}
}
`;
const result = await Tyr.graphql({ query });
const expected = {
data: {
users: [
{
name: 'ben',
teamIds: [
{
name: 'burritoMakers',
organizationId: {
name: 'Chipotle'
}
}
]
},
{
name: 'ted',
teamIds: []
},
{
name: 'noTeams',
teamIds: []
}
]
}
};
t.deepEqual<ExecutionResult>(result, expected);
}
示例7: inspectOnSessionRequest
async function inspectOnSessionRequest(t: TestContext, requestStub: SinonStub) {
// Device record is serialized inside of `updateUserSession`. Checking original DeviceRecord properties.
const anyValues = [
"deliveryPlatform",
"language",
"timezone",
"browserVersion",
"sdkVersion",
"browserName",
"subscriptionState",
"operatingSystem",
"operatingSystemVersion",
"devicePlatform",
"deviceModel",
];
t.is(requestStub.callCount, 1);
t.not(requestStub.getCall(0), null);
const data: any = requestStub.getCall(0).args[1];
anyValues.forEach((valueKey) => {
t.not(data[valueKey], undefined, `on_session: ${valueKey} is undefined! => data: ${JSON.stringify(data)}`);
});
}
示例8: forBestFormats
async function forBestFormats(t: TestContext, presetName: string): Promise<void> {
let preset = prepPreset(DefaultPresets.find(p => p.name === presetName));
const format = await getBestFormats('https://www.youtube.com/watch?v=oVXg7Grp1W8', preset);
let skipVideo = false;
let skipAudio = false;
if (preset.videoSort) {
t.truthy(format.video);
t.true(format.video.resolution <= preset.maxResolution);
} else {
skipVideo = true;
}
if (preset.audioSort) {
t.truthy(format.audio);
t.true(format.audio.audioBitrate <= preset.maxAudioBitrate);
} else {
skipAudio = true;
}
if (skipAudio && skipVideo) t.fail();
}
示例9: async
fn: async (t: TestContext) => {
const ted = await Tyr.byName.user.findOne({ query: { name: 'ted' } });
if (!ted) {
throw new Error(`No ted`);
}
const query = `
query getUserById($id: [ID]) {
user(_id: $id) {
name
teamIds {
name,
organizationId {
name
}
}
}
}
`;
const result = await Tyr.graphql({
query,
variables: {
id: [ted.$id]
}
});
const expected = {
data: {
user: {
name: 'ted',
teamIds: [
{
name: 'cavaEngineers',
organizationId: {
name: 'Cava'
}
}
]
}
}
};
t.deepEqual<ExecutionResult>(result, expected);
}
示例10: async
fn: async (t: TestContext) => {
const orgId = 'organizationId';
const gql = Tyr.graphql;
const result = await gql`
query userNameQuery {
users {
name
${orgId} {
name
}
}
}
`;
const expected = {
data: {
users: [
{
name: 'ben',
organizationId: {
name: 'Chipotle'
}
},
{
name: 'ted',
organizationId: {
name: 'Cava'
}
},
{
name: 'noTeams',
organizationId: {
name: 'Chipotle'
}
}
]
}
};
t.deepEqual<ExecutionResult>(result, expected);
}