Socket
Socket
Sign inDemoInstall

mockjs

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockjs - npm Package Compare versions

Comparing version 1.0.1-beta1 to 1.0.1-beta2

2

package.json

@@ -5,3 +5,3 @@ {

"description": "生成随机数据 & 拦截 Ajax 请求",
"version": "1.0.1-beta1",
"version": "1.0.1-beta2",
"homepage": "http://mockjs.com/",

@@ -8,0 +8,0 @@ "keywords": [

@@ -32,3 +32,3 @@ /* global require, module, window */

Mock.version = '1.0.1-beta1'
Mock.version = '1.0.1-beta2'

@@ -35,0 +35,0 @@ // 避免循环依赖

@@ -14,3 +14,3 @@ /* global window, document, location, Event, setTimeout */

new window.ActiveXObject("Microsoft.XMLHTTP")
关键方法的逻辑:

@@ -24,3 +24,3 @@ * new 此时尚无法确定是否需要拦截,所以创建原生 XHR 对象是必须的。

http://www.w3.org/TR/XMLHttpRequest2/
参考实现:

@@ -86,3 +86,3 @@ https://github.com/philikon/MockHttpRequest/blob/master/lib/mock.js

var XHR_EVENTS = 'readystatechange loadstart progress abort error load timeout loadend'.split(' ')
var XHR_REQUEST_PROPERTIES = 'timeout withCredentials'.split(' ')
var XHR_RESPONSE_PROPERTIES = 'readyState responseURL status statusText responseType response responseText responseXML'.split(' ')

@@ -205,3 +205,3 @@

// 同步属性 NativeXMLHttpRequest => MockXMLHttpRequest
for (var i = 0, len = XHR_RESPONSE_PROPERTIES.length; i < len; i++) {
for (var i = 0; i < XHR_RESPONSE_PROPERTIES.length; i++) {
try {

@@ -230,2 +230,9 @@ that[XHR_RESPONSE_PROPERTIES[i]] = xhr[XHR_RESPONSE_PROPERTIES[i]]

// 同步属性 MockXMLHttpRequest => NativeXMLHttpRequest
for (var j = 0; j < XHR_REQUEST_PROPERTIES.length; j++) {
try {
xhr[XHR_REQUEST_PROPERTIES[j]] = that[XHR_REQUEST_PROPERTIES[j]]
} catch (e) {}
}
return

@@ -288,3 +295,5 @@ }

that.statusText = HTTP_STATUS_CODES[200]
that.responseText = JSON.stringify(
// fix #92 #93 by @qddegtya
that.response = that.responseText = JSON.stringify(
convert(that.custom.template, that.custom.options),

@@ -295,5 +304,5 @@ null, 4

that.readyState = MockXMLHttpRequest.DONE
that.dispatchEvent(new Event('readystatechange'/*, false, false, that*/))
that.dispatchEvent(new Event('load'/*, false, false, that*/));
that.dispatchEvent(new Event('loadend'/*, false, false, that*/));
that.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ ))
that.dispatchEvent(new Event('load' /*, false, false, that*/ ));
that.dispatchEvent(new Event('loadend' /*, false, false, that*/ ));
}

@@ -350,3 +359,3 @@ },

overrideMimeType: function( /*mime*/ ) {},
responseType: '', // '', 'text', 'arraybuffer', 'blob', 'document', 'json'
responseType: '', // '', 'text', 'arraybuffer', 'blob', 'document', 'json'
response: null,

@@ -353,0 +362,0 @@ responseText: '',

@@ -63,2 +63,31 @@ /* global console, require, chai, describe, before, it */

})
describe('jQuery.ajax() XHR Fields', function() {
it('', function(done) {
var that = this
var url = Math.random()
var xhr
$.ajax({
xhr: function() {
xhr = $.ajaxSettings.xhr()
return xhr
},
url: url,
dataType: 'json',
xhrFields: {
timeout: 123,
withCredentials: true
}
}).done(function( /*data, textStatus, jqXHR*/ ) {
// 不会进入
}).fail(function(jqXHR /*, textStatus, errorThrown*/ ) {
// 浏览器 || PhantomJS
expect([404, 0]).to.include(jqXHR.status)
that.test.title += url + ' => ' + jqXHR.status
expect(xhr.timeout).to.be.equal(123)
expect(xhr.withCredentials).to.be.equal(true)
}).always(function() {
done()
})
})
})

@@ -65,0 +94,0 @@ describe('Mock.mock( rurl, template )', function() {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc