当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mockjs.mock函数代码示例

本文整理汇总了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
  )
}
开发者ID:zerolugithub,项目名称:rap2-delos,代码行数:11,代码来源:bo.ts

示例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
 })
开发者ID:tonyjt,项目名称:rap2-delos,代码行数:24,代码来源:foreign.ts

示例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) {
开发者ID:wexz,项目名称:delon,代码行数:31,代码来源:mock.service.spec.ts

示例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 }]
    })
};
开发者ID:duxie,项目名称:ng-alain,代码行数:30,代码来源:_chart.ts

示例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 === '普通') {
//.........这里部分代码省略.........
开发者ID:tonyjt,项目名称:rap2-delos,代码行数:101,代码来源:foreign.ts


注:本文中的mockjs.mock函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。