-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added jquery example, fix issue with jquery, added .mock override wit…
…h shortcut
- Loading branch information
James Newell
committed
Dec 28, 2014
1 parent
7677965
commit 1720d69
Showing
6 changed files
with
148 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
{ | ||
"name": "xhr-mock", | ||
"scripts": ["index.js", "lib/MockXMLHttpRequest.js"] | ||
"scripts": ["index.js", "lib/MockXMLHttpRequest.js"], | ||
"development": { | ||
"dependencies": { | ||
"component/assert": "*" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>jQuery Example — xhr-mock</title> | ||
</head> | ||
<body> | ||
|
||
<h1>xhr-mock</h1> | ||
<h2>jQuery Example</h2> | ||
|
||
<script src="https://code.jquery.com/jquery-2.1.3.js"></script> | ||
<script src="../build/build.js"></script> | ||
<script> | ||
|
||
var mock = require('xhr-mock'); | ||
mock.setup(); | ||
|
||
mock.get('http://google.com/', function(request) { | ||
request.status = 200; | ||
request.responseText = '<h1>Google</h1>'; | ||
}); | ||
|
||
// --------- | ||
|
||
$.get('http://google.com/', function(data, textStatus, jqXHR) { | ||
console.log(arguments); | ||
}).fail(function() { | ||
console.log('ERROR'); | ||
}); | ||
|
||
// --------- | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var assert = require('assert'); | ||
var mock = require('xhr-mock'); | ||
|
||
describe('xhr-mock', function() { | ||
|
||
describe('.setup() and teardown()', function() { | ||
|
||
it('should setup and teardown the mock XMLHttpRequest class', function() { | ||
|
||
var xhr = window.XMLHttpRequest; | ||
mock.setup(); | ||
assert.notEqual(window.XMLHttpRequest, xhr); | ||
mock.teardown(); | ||
assert.equal(window.XMLHttpRequest, xhr); | ||
|
||
}); | ||
|
||
it('should remove any handlers', function() { | ||
|
||
mock.get('http://www.google.com/', function() {}); | ||
mock.setup(); | ||
assert.equal(mock.XMLHttpRequest.handlers.length, 0); | ||
mock.get('http://www.google.com/', function() {}); | ||
mock.teardown(); | ||
assert.equal(mock.XMLHttpRequest.handlers.length, 0); | ||
|
||
|
||
}); | ||
|
||
}); | ||
|
||
|
||
|
||
|
||
}); |