react-native-fetch-mock -
MIT
跨平台
Objective-C
软件简介
在使用 React Native 的过程中,没有找到一款合适自己的 fetch-mock 组件。
因此,决定自己发布一个 react-native-fetch-mock module。
Roadmap
1. 结合Mock.js(已实现)
2. 配合线上rap系统
Usage
mocks/index.js
export default {
'/api/path': (options) => {
const all = Mock.mock({
'list|2': [{
'id|+1': 1,
'name': '@first @last',
'age|18-54': 1,
}]
}).list;
return Promise.resolve({
data: all,
});
}
}
index.js
import FetchMock from 'react-native-fetch-mock';
if (__dev__) {
global.fetch = new FetchMock(require('path/to/mocks/directory')).fetch;
}
// if __dev__ is true, it will back the data you defined in mock directory
fetch('/api/path', options);