Skip to content

Commit 1b9c99e

Browse files
committed
Add mockjs example
1 parent fd8af34 commit 1b9c99e

File tree

103 files changed

+6771
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+6771
-10
lines changed

__mocks__/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Mock } from '../';
12

23
export default {
34
'/api/users': async (options) => {
@@ -32,5 +33,35 @@ export default {
3233
return {
3334
data: filtered,
3435
}
36+
},
37+
'/api/users/mockjs': async (options) => {
38+
const all = Mock.mock({
39+
'list|2': [{
40+
'id|+1': 1,
41+
'name': '@first @last',
42+
'age|18-54': 1,
43+
}]
44+
}).list;
45+
let filtered;
46+
if ('undefined' !== typeof options) {
47+
filtered = all.filter(item => {
48+
let result = true;
49+
const keys = Object.keys(options);
50+
keys.forEach(key => {
51+
const option = options[key];
52+
53+
if (item[key] && item[key] !== option) {
54+
result = false;
55+
}
56+
});
57+
58+
return result;
59+
});
60+
} else {
61+
filtered = all;
62+
}
63+
return {
64+
data: filtered,
65+
}
3566
}
3667
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)