fixing js unit tests

This commit is contained in:
Thomas Müller 2014-03-05 01:10:39 +01:00
parent 5f711912a1
commit 33b798c3d6
3 changed files with 5 additions and 11 deletions

View file

@ -17,7 +17,6 @@
"eventsource.js",
"config.js",
"multiselect.js",
"router.js",
"oc-requesttoken.js"
]
}

View file

@ -87,6 +87,7 @@ window.oc_defaults = {};
// custom responses
window.fakeServer = fakeServer;
OC.Router = {};
OC.Router.routes = [];
OC.Router.routes_request = {
state: sinon.stub().returns('resolved'),

View file

@ -179,7 +179,7 @@ describe('Core base tests', function() {
});
it('Encodes special characters', function() {
expect(OC.buildQueryString({
unicode: '汉字',
unicode: '汉字'
})).toEqual('unicode=%E6%B1%89%E5%AD%97');
expect(OC.buildQueryString({
b: 'spaace value',
@ -199,22 +199,20 @@ describe('Core base tests', function() {
'booleantrue': true
})).toEqual('booleanfalse=false&booleantrue=true');
expect(OC.buildQueryString({
'number': 123,
'number': 123
})).toEqual('number=123');
});
});
describe('Session heartbeat', function() {
var clock,
oldConfig,
loadedStub,
routeStub,
counter;
beforeEach(function() {
clock = sinon.useFakeTimers();
oldConfig = window.oc_config;
loadedStub = sinon.stub(OC.Router, 'registerLoadedCallback');
routeStub = sinon.stub(OC.Router, 'generate').returns('/heartbeat');
routeStub = sinon.stub(OC, 'generateUrl').returns('/heartbeat');
counter = 0;
fakeServer.autoRespond = true;
@ -227,7 +225,6 @@ describe('Core base tests', function() {
afterEach(function() {
clock.restore();
window.oc_config = oldConfig;
loadedStub.restore();
routeStub.restore();
});
it('sends heartbeat half the session lifetime when heartbeat enabled', function() {
@ -236,9 +233,7 @@ describe('Core base tests', function() {
session_lifetime: 300
};
window.initCore();
expect(loadedStub.calledOnce).toEqual(true);
loadedStub.yield();
expect(routeStub.calledWith('heartbeat')).toEqual(true);
expect(routeStub.calledWith('/heartbeat')).toEqual(true);
expect(counter).toEqual(0);
@ -264,7 +259,6 @@ describe('Core base tests', function() {
session_lifetime: 300
};
window.initCore();
expect(loadedStub.notCalled).toEqual(true);
expect(routeStub.notCalled).toEqual(true);
expect(counter).toEqual(0);