mock-variable
[WIP] Generate fake / mock structured variable in a modern, human-readable way.
用一个现代的、可读的的方式来生成用于测试的假数据。
1. Install
npm i --save mock-variable
Then import it.
; // ES6var MV = ; // ES5 with npm
2. API & Mocker
You can assemble the variable structure arbitrarily by using the mockers below:
- MV.bool()
- MV.number(min[, max = min, fixed = 0])
- MV.string([len = 8])
- MV.arrayOf(mocker[, min = 20, max = min])
- MV.shape(mockerObject)
- MV.oneOf(valueArray)
- MV.constant(value)
- MV.apply(Function)
After you got the mocker, then use mocker.mock()
to get the fake data.
You can see all the usage in the test cases file.
If more Mocker
are needed, welcome to send a pull request
, or put an issue to me.
3. Usage examples
Here is some examples. More you can see in tests/test.js file.
- Simple usage
MV; // 4.71MV; // `Qv_teE`MV; // true / falseMV; // random element from the arrayMV; // `hello, hustcc`MV; // got nullMV); // will got number generate by fucntion Math.random()
arrayOf
var mocker = MV; mocker; // got an array which contains string, and array length 10 ~ 20.
shape
var mocker = MVshape name: MV id: MV sex: MV city: 'hz'; mocker; // got a random value object.
- complex usage
var mocker = MV; mocker; // will got an array of users, and the list's length is 20.
4. Test
npm i
npm t
License
ISC@hustcc.