/* global require, chai, describe, before, it */ // 数据占位符定义(Data Placeholder Definition,DPD) import { expect } from 'chai'; import Mock from '../src/mock'; import _ from 'underscore'; const G = { test: { title: 'Mock', }, }; describe('Mock.mock', function () { describe('Mock.mock( String )', function () { it('@EMAIL', function () { var data = Mock.mock(G.test.title); expect(data).to.not.equal(G.test.title); G.test.title += ' => ' + data; }); }); describe('Mock.mock( {} )', function () { it('', function () { var tpl = { 'list|1-10': [ { 'id|+1': 1, email: '@EMAIL', }, ], }; var data = Mock.mock(tpl); G.test.title = JSON.stringify(tpl /*, null, 4*/) + ' => ' + JSON.stringify(data /*, null, 4*/); expect(data).to.have.property('list').that.be.an('array').with.length.within(1, 10); _.each(data.list, function (item, index, list) { if (index > 0) expect(item.id).to.equal(list[index - 1].id + 1); }); }); }); describe('Mock.mock( function() )', function () { it('', function () { var fn = function () { return Mock.mock({ 'list|1-10': [ { 'id|+1': 1, email: '@EMAIL', }, ], }); }; var data = Mock.mock(fn); G.test.title = fn.toString() + ' => ' + JSON.stringify(data /*, null, 4*/); expect(data).to.have.property('list').that.be.an('array').with.length.within(1, 10); _.each(data.list, function (item, index, list) { if (index > 0) expect(item.id).to.equal(list[index - 1].id + 1); }); }); }); });