Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
renderjs
Commits
2a499e62
Commit
2a499e62
authored
Aug 05, 2013
by
Romain Courteaud
🐸
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sinon fake server usage.
parent
e571f2f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
32 deletions
+21
-32
sinon-qunit.js
sinon-qunit.js
+0
-14
test/renderjs_test.js
test/renderjs_test.js
+21
-18
No files found.
sinon-qunit.js
View file @
2a499e62
...
...
@@ -3,7 +3,6 @@
*
* @author Gustavo Machado (@machadogj), Jose Romaniello (@jfroma)
* Modified version of sinon-qunit from Christian Johansen
* Modified version of sinon-qunit from Romain Courteaud
*
* (The BSD License)
*
...
...
@@ -46,24 +45,11 @@ sinon.config = {
injectIntoThis
:
true
,
injectInto
:
null
,
properties
:
[
"
spy
"
,
"
stub
"
,
"
mock
"
,
"
clock
"
,
"
sandbox
"
],
// useFakeTimers: true,
// useFakeServer: false
useFakeTimers
:
false
,
useFakeServer
:
true
};
(
function
(
global
)
{
var
qTest
=
QUnit
.
test
;
QUnit
.
test
=
global
.
test
=
function
(
testName
,
expected
,
callback
,
async
)
{
if
(
arguments
.
length
===
2
)
{
callback
=
expected
;
expected
=
null
;
}
return
qTest
(
testName
,
expected
,
sinon
.
test
(
callback
),
async
);
};
var
qModule
=
QUnit
.
module
;
var
setup
=
function
()
{
...
...
test/renderjs_test.js
View file @
2a499e62
/*global window, document, QUnit, jQuery, renderJS, RenderJSGadget */
/*global window, document, QUnit, jQuery, renderJS, RenderJSGadget
, sinon
*/
/*jslint indent: 2, maxerr: 3, maxlen: 79 */
"
use strict
"
;
(
function
(
document
,
$
,
renderJS
,
QUnit
)
{
(
function
(
document
,
$
,
renderJS
,
QUnit
,
sinon
)
{
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
...
...
@@ -285,7 +285,7 @@
});
test
(
'
Ajax error reject the promise
'
,
function
()
{
// Check that declareGadgetKlass fails if ajax fails
var
server
=
this
.
sandbox
.
useFakeServer
(),
var
server
=
sinon
.
fakeServer
.
create
(),
url
=
'
https://example.org/files/qunittest/test
'
;
server
.
respondWith
(
"
GET
"
,
url
,
[
404
,
{
...
...
@@ -308,7 +308,7 @@
test
(
'
Non HTML reject the promise
'
,
function
()
{
// Check that declareGadgetKlass fails if non html is retrieved
var
server
=
this
.
sandbox
.
useFakeServer
(),
var
server
=
sinon
.
fakeServer
.
create
(),
url
=
'
https://example.org/files/qunittest/test
'
;
server
.
respondWith
(
"
GET
"
,
url
,
[
200
,
{
...
...
@@ -333,7 +333,7 @@
test
(
'
HTML parsing failure reject the promise
'
,
function
()
{
// Check that declareGadgetKlass fails if the html can not be parsed
var
server
=
this
.
sandbox
.
useFakeServer
(),
var
server
=
sinon
.
fakeServer
.
create
(),
url
=
'
https://example.org/files/qunittest/test
'
,
mock
;
...
...
@@ -365,7 +365,7 @@
test
(
'
Klass creation
'
,
function
()
{
// Check that declareGadgetKlass returns a subclass of RenderJSGadget
// and contains all extracted properties on the prototype
var
server
=
this
.
sandbox
.
useFakeServer
(),
var
server
=
sinon
.
fakeServer
.
create
(),
url
=
'
https://example.org/files/qunittest/test
'
,
mock
;
...
...
@@ -404,7 +404,7 @@
test
(
'
Klass is not reloaded if called twice
'
,
function
()
{
// Check that declareGadgetKlass does not reload the gadget
// if it has already been loaded
var
server
=
this
.
sandbox
.
useFakeServer
(),
var
server
=
sinon
.
fakeServer
.
create
(),
url
=
'
https://example.org/files/qunittest/test
'
,
mock
;
...
...
@@ -714,7 +714,7 @@
test
(
'
clearGadgetKlassList leads to gadget reload
'
,
function
()
{
// Check that declareGadgetKlass reload the gadget
// after clearGadgetKlassList is called
var
server
=
this
.
sandbox
.
useFakeServer
(),
var
server
=
sinon
.
fakeServer
.
create
(),
url
=
'
https://example.org/files/qunittest/test
'
,
mock
;
...
...
@@ -1199,7 +1199,7 @@
test
(
'
returns a Promise
'
,
function
()
{
// Check that declareGadget return a Promise
var
gadget
=
new
RenderJSGadget
(),
server
=
this
.
sandbox
.
useFakeServer
(),
server
=
sinon
.
fakeServer
.
create
(),
url
=
'
https://example.org/files/qunittest/test
'
,
html
=
"
<html>
"
+
"
<body>
"
+
...
...
@@ -1223,7 +1223,7 @@
test
(
'
provide a gadget instance as callback parameter
'
,
function
()
{
// Check that declare gadget returns the gadget
var
gadget
=
new
RenderJSGadget
(),
server
=
this
.
sandbox
.
useFakeServer
(),
server
=
sinon
.
fakeServer
.
create
(),
url
=
'
https://example.org/files/qunittest/test
'
,
html
=
"
<html>
"
+
"
<body>
"
+
...
...
@@ -1262,13 +1262,16 @@
test
(
'
load dependency before returning gadget
'
,
function
()
{
// Check that dependencies are loaded before gadget creation
var
gadget
=
new
RenderJSGadget
(),
server
=
this
.
sandbox
.
useFakeServer
(),
server
=
sinon
.
fakeServer
.
create
(),
html_url
=
'
https://example.org/files/qunittest/test2.html
'
,
js1_url
=
"
data:application/javascript;base64,
"
+
window
.
btoa
(
"
$('#qunit-fixture').find('div').first().text('youhou');
"
),
js2_url
=
js1_url
,
js2_url
=
"
data:application/javascript;base64,
"
+
window
.
btoa
(
"
$('#qunit-fixture').find('div').first().text('youhou2');
"
),
css1_url
=
"
data:text/plain;base64,
"
+
window
.
btoa
(
""
),
css2_url
=
css1_url
,
...
...
@@ -1303,7 +1306,7 @@
gadget
.
declareGadget
(
html_url
,
$
(
'
#qunit-fixture
'
).
find
(
"
div
"
).
last
())
.
done
(
function
(
new_gadget
)
{
equal
(
$
(
'
#qunit-fixture
'
).
html
(),
"
<div>youhou</div><div><p>Bar content</p></div>
"
);
"
<div>youhou
2
</div><div><p>Bar content</p></div>
"
);
ok
(
spy_js
.
calledTwice
,
"
JS count
"
+
spy_js
.
callCount
);
equal
(
spy_js
.
firstCall
.
args
[
0
],
js1_url
,
"
First JS call
"
);
equal
(
spy_js
.
secondCall
.
args
[
0
],
js2_url
,
"
Second JS call
"
);
...
...
@@ -1323,7 +1326,7 @@
test
(
'
Fail if klass can not be loaded
'
,
function
()
{
// Check that gadget is not created if klass is can not be loaded
var
gadget
=
new
RenderJSGadget
(),
server
=
this
.
sandbox
.
useFakeServer
(),
server
=
sinon
.
fakeServer
.
create
(),
html_url
=
'
https://example.org/files/qunittest/test3.html
'
;
server
.
respondWith
(
"
GET
"
,
html_url
,
[
404
,
{
...
...
@@ -1347,7 +1350,7 @@
test
(
'
Fail if js can not be loaded
'
,
function
()
{
// Check that dependencies are loaded before gadget creation
var
gadget
=
new
RenderJSGadget
(),
server
=
this
.
sandbox
.
useFakeServer
(),
server
=
sinon
.
fakeServer
.
create
(),
html_url
=
'
https://example.org/files/qunittest/test2.html
'
,
js1_url
=
'
foo://bar2
'
,
mock
;
...
...
@@ -1379,7 +1382,7 @@
test
(
'
Do not load gadget dependency twice
'
,
function
()
{
// Check that dependencies are not reloaded if 2 gadgets are created
var
gadget
=
new
RenderJSGadget
(),
server
=
this
.
sandbox
.
useFakeServer
(),
server
=
sinon
.
fakeServer
.
create
(),
html_url
=
'
https://example.org/files/qunittest/test2.html
'
,
js1_url
=
"
data:application/javascript;base64,
"
+
window
.
btoa
(
...
...
@@ -1430,7 +1433,7 @@
test
(
'
Load 2 concurrent gadgets in parallel
'
,
function
()
{
// Check that dependencies are loaded once if 2 gadgets are created
var
gadget
=
new
RenderJSGadget
(),
server
=
this
.
sandbox
.
useFakeServer
(),
server
=
sinon
.
fakeServer
.
create
(),
html_url
=
'
https://example.org/files/qunittest/test2.html
'
,
mock
,
spy
;
...
...
@@ -1457,4 +1460,4 @@
server
.
respond
();
});
}(
document
,
jQuery
,
renderJS
,
QUnit
));
}(
document
,
jQuery
,
renderJS
,
QUnit
,
sinon
));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment