Permalink
Browse files

0.2.1 lint and build

  • Loading branch information...
1 parent 98e00a3 commit 959a15303ce370690e15fcb4cf98bbb33fa25b23 @leobalter committed Jul 24, 2012
Showing with 48 additions and 24 deletions.
  1. +33 −9 dist/Dexter.js
  2. +2 −2 dist/Dexter.min.js
  3. +1 −1 package.json
  4. +11 −11 src/Dexter.fakeXHR.js
  5. +1 −1 test/unit/spy.js
View
@@ -1,4 +1,4 @@
-/*! Dexter JS - v0.1.0 - 2012-07-18
+/*! Dexter JS - v0.2.1 - 2012-07-24
* https://github.com/leobalter/DexterJS
* Copyright (c) 2012 Leonardo Balter; Licensed MIT, GPL */
@@ -18,12 +18,14 @@
actions = {
'spy' : function( that, args ) {
+ // call order issues
+ var returned = that._oldCall.apply( this, args );
+
if ( typeof( that.callback ) === 'function' ) {
- that.callback.apply( this, args );
+ that.callback.apply( this, args );
}
// calls the original method
- return that._oldCall.apply( this, args );
-
+ return returned;
},
'stub' : function( that, args ) {
if ( typeof( that.callback ) === 'function' ) {
@@ -198,7 +200,7 @@
***/
function verifyState( state, sendFlag ) {
if ( state !== 1 || sendFlag ) {
- throw new Error( 'INVALID_STATE_ERR' );
+ throw new Error( 'INVALID_STATE_ERR' );
}
}
@@ -338,19 +340,30 @@
* fake .send
***/
send : function( data ) {
+ var reqHeaders;
// readyState verification (xhr should be already opened)
verifyState( this.readyState, this.sendFlag );
+ if ( !/^(get|head)$/i.test( this.method ) ) {
+ if (this.requestHeaders[ 'Content-Type' ]) {
+ reqHeaders = this.requestHeaders[ 'Content-Type' ].split( ';' );
+ this.requestHeaders[ 'Content-Type' ] = reqHeaders[ 0 ] + ';charset=utf-8';
+ } else {
+ this.requestHeaders[ 'Content-Type' ] = "text/plain;charset=utf-8";
+ }
+ this.requestBody = data;
+ }
+
// setting properties
this.errorFlag = false;
- this.sendFlag = this.async;
+ this.sendFlag = true; // this.async;
// trigger readystatechange with Opened status
this.__DexterStateChange( this.OPENED );
// hummm if think I won´t need this, omg, where´s the specification
if ( typeof( this.onSend ) === 'function' ) {
- this.onSend( this );
+ this.onSend( this );
}
},
/***
@@ -581,7 +594,6 @@
* its returned object. Not on the XHR itself.
***/
CreateFakeXHR.prototype = {
- // TODO: test
/***
* interface to export xhr.__DexterRespond and set this.doneRequests
***/
@@ -603,10 +615,22 @@
this.doneRequests.push( xhr );
},
/***
+ * uses a Dexter.spy on xhr send requests
+ ***/
+ spy : function( callback ) {
+ var spy = Dexter.spy( fakeXHRObj, 'send', callback );
+ // this.__spy will be used on .restore();
+ this.__spy = spy;
+ return spy;
+ },
+ /***
* restore the XHR objects to their original states, defaking them
* this won´t affect already created fake ajax requests.
***/
restore : function() {
+ if ( this.__spy ) {
+ this.__spy.restore();
+ }
if ( ajaxObjs.xhr ) {
globalObj.XMLHttpRequest = ajaxObjs.xhr;
}
@@ -624,4 +648,4 @@
return new CreateFakeXHR();
};
-}( this, Dexter ));
+}( this, Dexter ));
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -2,7 +2,7 @@
"name": "Dexter",
"title": "Dexter JS",
"description": "Dexter is a simple Test Helper, framework independent.",
- "version": "0.1.0",
+ "version": "0.2.1",
"homepage": "https://github.com/leobalter/DexterJS",
"author": {
"name": "Leonardo Balter",
View
@@ -263,14 +263,14 @@
* fake .send
***/
send : function( data ) {
- var reqHeaders;
+ var reqHeaders;
// readyState verification (xhr should be already opened)
verifyState( this.readyState, this.sendFlag );
- if ( !/^(get|head)$/i.test( this.method ) ) {
- if (this.requestHeaders[ 'Content-Type' ]) {
+ if ( !/^(get|head)$/i.test( this.method ) ) {
+ if (this.requestHeaders[ 'Content-Type' ]) {
reqHeaders = this.requestHeaders[ 'Content-Type' ].split( ';' );
- this.requestHeaders[ 'Content-Type' ] = value[ 0 ] + ';charset=utf-8';
+ this.requestHeaders[ 'Content-Type' ] = reqHeaders[ 0 ] + ';charset=utf-8';
} else {
this.requestHeaders[ 'Content-Type' ] = "text/plain;charset=utf-8";
}
@@ -541,19 +541,19 @@
* uses a Dexter.spy on xhr send requests
***/
spy : function( callback ) {
- var spy = Dexter.spy( fakeXHRObj, 'send', callback );
- // this.__spy will be used on .restore();
- this.__spy = spy;
- return spy;
+ var spy = Dexter.spy( fakeXHRObj, 'send', callback );
+ // this.__spy will be used on .restore();
+ this.__spy = spy;
+ return spy;
},
/***
* restore the XHR objects to their original states, defaking them
* this won´t affect already created fake ajax requests.
***/
restore : function() {
- if ( this.__spy ) {
- this.__spy.restore();
- }
+ if ( this.__spy ) {
+ this.__spy.restore();
+ }
if ( ajaxObjs.xhr ) {
globalObj.XMLHttpRequest = ajaxObjs.xhr;
}
View
@@ -102,7 +102,7 @@
Dexter.__bar__ = function() {
foo = 'a';
- }
+ };
Dexter.spy( Dexter, '__bar__', function() {
foo += 'b';

0 comments on commit 959a153

Please sign in to comment.