Browse Source

mock bug fixed

hare8999@163.com 3 years ago
parent
commit
1de400df85
2 changed files with 9 additions and 3 deletions
  1. 8 2
      mock/index.js
  2. 1 1
      src/main.js

+ 8 - 2
mock/index.js

@@ -1,10 +1,13 @@
 const Mock = require('mockjs')
 const { param2Obj } = require('./utils')
 
+let mocks = []
+
 // for front mock
 // please use it cautiously, it will redefine XMLHttpRequest,
 // which will cause many of your third-party libraries to be invalidated(like progress event).
-function mockXHR(mocks) {
+function mockXHR(inputMocks) {
+  mocks = inputMocks
   // mock patch
   // https://github.com/nuysoft/Mock/issues/300
   Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
@@ -42,5 +45,8 @@ function mockXHR(mocks) {
   }
 }
 
-module.exports = mockXHR
+module.exports = {
+  mockXHR,
+  mocks,
+}
 

+ 1 - 1
src/main.js

@@ -123,7 +123,7 @@ if (process.env.NODE_ENV === 'development') {
     .reduce(function(prev, current) {
       return prev.concat(current)
     }, [])
-  const mockXHR = require('../mock')
+  const { mockXHR } = require('../mock')
   mockXHR(mocks)
 }