test.mock.mock.js
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* global require, chai, describe, before, it */
// 数据占位符定义(Data Placeholder Definition,DPD)
var expect = chai.expect
var Mock, $, _
describe('Mock.mock', function() {
before(function(done) {
require(['mock', 'underscore', 'jquery'], function() {
Mock = arguments[0]
_ = arguments[1]
$ = arguments[2]
expect(Mock).to.not.equal(undefined)
expect(_).to.not.equal(undefined)
expect($).to.not.equal(undefined)
done()
})
})
describe('Mock.mock( String )', function() {
it('@EMAIL', function() {
var data = Mock.mock(this.test.title)
expect(data).to.not.equal(this.test.title)
this.test.title += ' => ' + data
})
})
describe('Mock.mock( {} )', function() {
it('', function() {
var tpl = {
'list|1-10': [{
'id|+1': 1,
'email': '@EMAIL'
}]
}
var data = Mock.mock(tpl)
this.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)
this.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)
})
})
})
})