123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- 'use strict';
- /**
- * 辅助方法扩展 单元测试
- *
- * @author Mai
- * @data 2018/4/20
- * @version
- */
- const { app, assert } = require('egg-mock/bootstrap');
- describe('test/app/extend/helper.test.js', () => {
- it('ValidTemplateCode test', function () {
- const ctx = app.mockContext();
- assert(ctx.helper.ValidTemplateCode('z') === true);
- assert(ctx.helper.ValidTemplateCode('Z') === true);
- assert(ctx.helper.ValidTemplateCode('-') === false);
- assert(ctx.helper.ValidTemplateCode('1') === false);
- assert(ctx.helper.ValidTemplateCode('z1') === true);
- assert(ctx.helper.ValidTemplateCode('z1-') === false);
- assert(ctx.helper.ValidTemplateCode('zav') === true);
- assert(ctx.helper.ValidTemplateCode('z1-e') === true);
- assert(ctx.helper.ValidTemplateCode('z1-e-1') === true);
- });
- it('ValidTemplateIndexCode test', function () {
- const ctx = app.mockContext();
- assert(ctx.helper.ValidTemplateIndexCode('z2-d-d-1~z2-d-d-5 高填方路段处理 同z2-d-c-1~z2-d-c-5') === false);
- });
- it('validMatchCode test', function () {
- const ctx = app.mockContext();
- assert(ctx.helper.validMatchCode('1-1-1'));
- assert(ctx.helper.validMatchCode('1-1-X'));
- assert(ctx.helper.validMatchCode('1-X-1'));
- assert(!ctx.helper.validMatchCode('1-1-'));
- assert(!ctx.helper.validMatchCode('X-1-1'));
- assert(!ctx.helper.validMatchCode('1-人-1'));
- });
- it('loadJsonFile test', function () {
- const ctx = app.mockContext();
- const vJ = ctx.helper.loadJsonFile(app.baseDir + '/test/app/extend/test.json');
- assert(vJ.bills);
- assert(vJ.properties);
- });
- it('operationJson test', function () {
- const ctx = app.mockContext();
- let testjson = {name: 'hello'};
- const result = ctx.helper.operationJson(testjson,'ok','world');
- assert(result.ok === 'world');
- });
- });
|