本文整理汇总了TypeScript中mockjs.mock函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mock函数的具体用法?TypeScript mock怎么用?TypeScript mock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: mock
export const BO_REPOSITORY_FN = (source: any) => {
return Object.assign(
mock({
id: REPOSITORY_ID++,
name: '仓库@ctitle',
description: '@cparagraph',
logo: '@url'
}),
source
)
}
示例2: if
ret.cases = cases.map(function (theCase) {
let obj: any = {
caseDesc: theInterface.name + (theCase['$type'] || ''),
path: path + '?' + Helper.formatKV(theCase),
keyValue: JSON.stringify(theCase),
method: theInterface.method,
mode: 1, // 固定参数
moduleName: moduleName, // 冗余参数
// moduleId: moduleId,
projectId: roomProjectId,
rawData: '', // 天然为空
setUp: '', // 天然为空
tearDown: '', // 天然为空
userId: !ctx.session.empId ? '122033' : ctx.session.empId, // todo use empId
}
if (name === '普通') {
obj.expectResult = 'true_json'
obj.expectMessage = JSON.stringify(mock(Tree.ArrayToTreeToTemplate(responseProperties)))
} else if (name === '边界') {
obj.expectResult = 'false'
obj.expectMessage = 'error'
}
return obj
})
示例3: describe
import { Injector } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import * as Mock from 'mockjs';
import { MockService } from './mock.service';
import { MockStatusError } from './status.error';
import { DelonMockConfig } from '../mock.config';
import { DelonMockModule } from '../index';
import { MockRequest } from './interface';
const DATA = {
USERS: {
// 支持值为 Object 和 Array
'GET /users': { users: [1, 2] },
// GET 可省略
'/users/1': Mock.mock({ id: 1, 'rank|3': '★★★' }),
'/users/:id': (req: MockRequest) => {
return { id: req.params.id, s: 'detail' };
},
'/users/:id/edit': (req: MockRequest) => {
return { id: req.params.id, s: 'edit' };
},
'POST /users/1': { uid: 0, action: 'add' },
'/data/([0-9])': (req: MockRequest) => req,
},
};
describe('mock: service', () => {
let injector: Injector;
let srv: MockService = null;
function genModule(options: DelonMockConfig) {
示例4:
if (key !== 'name') {
radarData.push({
name: item.name,
label: radarTitleMap[key],
value: item[key]
});
}
});
});
// endregion
export const CHARTS = {
'/chart': Object.assign({}, {
visitData,
visitData2,
salesData,
searchData,
offlineData,
offlineChartData,
salesTypeData,
salesTypeDataOnline,
salesTypeDataOffline,
radarData
}),
'/chart/visit': Object.assign([], visitData),
'/chart/tags': Mock.mock({
'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }]
})
};
示例5: async
router.get('/foreign/room/params', async (ctx, next) => {
let {repositoryId, interfaceId, name} = ctx.query
if (!name || ['普通', '边界'].indexOf(name) === -1) {
name = '普通'
}
if (!ctx.session.empId) {
ctx.body = {
error: 'Need to login',
data: {},
}
}
if (!repositoryId) {
ctx.body = {
error: 'Need repositoryId',
data: {},
}
return next()
}
let [roomResult, theInterface] = await Promise.all([
Room.findOne({
where: { repositoryId },
}),
Interface.findOne({
where: { repositoryId, id: interfaceId },
include: [
QueryInclude.Properties,
],
} as any),
])
if (!theInterface) {
ctx.body.error = 'Cannot find interface corresponding to ' + interfaceId
return next()
}
let requestProperties = theInterface.properties.filter((item: any) => item.scope === 'request')
let responseProperties = theInterface.properties.filter((item: any) => item.scope === 'response')
let ret: any = {}
ctx.body = {
error: undefined,
data: ret,
}
if (!roomResult || !requestProperties.length) {
ctx.body.error = 'Not found'
return next()
}
let { roomProjectId, hostname } = roomResult
let cases = []
let standard = mock(Tree.ArrayToTreeToTemplate(requestProperties))
if (name === '普通') {
cases.push(standard)
} else if (name === '边界') {
for (let prop of requestProperties) {
let rules = Helper.generateRules(prop)
if (!rules) {
continue
}
// cases.push(standard)
for (let rule of rules) {
let obj = _.clone(standard)
obj[prop.name] = rule
Object.defineProperty(obj, '$type', {
value: rule['$type'],
})
cases.push(obj)
}
}
}
let moduleName = theInterface.name + '-自动' + name + '验证'
let path = new URL(theInterface.url, hostname).toString()
ret.module = {
moduleName: moduleName,
projectId: roomProjectId,
}
ret.cases = cases.map(function (theCase) {
let obj: any = {
caseDesc: theInterface.name + (theCase['$type'] || ''),
path: path + '?' + Helper.formatKV(theCase),
keyValue: JSON.stringify(theCase),
method: theInterface.method,
mode: 1, // 固定参数
moduleName: moduleName, // 冗余参数
// moduleId: moduleId,
projectId: roomProjectId,
rawData: '', // 天然为空
setUp: '', // 天然为空
tearDown: '', // 天然为空
userId: !ctx.session.empId ? '122033' : ctx.session.empId, // todo use empId
}
if (name === '普通') {
//.........这里部分代码省略.........