Minor cleanups
This commit is contained in:
parent
d3b1fa8937
commit
cd101b5120
@ -38,7 +38,7 @@ export default class uObserve {
|
||||
} else if (typeof p1 === 'function') {
|
||||
this.observeRecursive(obj, p1);
|
||||
} else {
|
||||
throw new Error('Invalid arguments');
|
||||
throw new Error('Invalid argument for observe');
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ export default class uObserve {
|
||||
this.unobserveRecursive(obj, p1);
|
||||
}
|
||||
} else {
|
||||
throw new Error('Invalid arguments');
|
||||
throw new Error('Invalid argument for unobserve');
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,10 +295,10 @@ export default class uObserve {
|
||||
return;
|
||||
}
|
||||
observers = obj._observers[property];
|
||||
console.log(`Removing observer for ${property}…`)
|
||||
console.log(`Removing observer for ${property}…`);
|
||||
} else {
|
||||
observers = obj._observers;
|
||||
console.log('Removing observer for object…')
|
||||
console.log('Removing observer for object…');
|
||||
}
|
||||
observers.forEach((obs) => {
|
||||
if (obs === observer) {
|
||||
|
@ -35,10 +35,10 @@ import uUtils from './utils.js';
|
||||
* @property {string} trackname
|
||||
* @property {number} trackid
|
||||
* @property {number} timestamp
|
||||
* @property {number} distance
|
||||
* @property {number} seconds
|
||||
* @property {number} totalDistance
|
||||
* @property {number} totalSeconds
|
||||
* @property {number} meters Distance to previous position
|
||||
* @property {number} seconds Time difference to previous position
|
||||
* @property {number} totalMeters Distance to first position
|
||||
* @property {number} totalSeconds Time difference to first position
|
||||
*/
|
||||
export default class uPosition {
|
||||
|
||||
@ -63,9 +63,9 @@ export default class uPosition {
|
||||
position.trackname = uUtils.getString(pos.trackname);
|
||||
position.trackid = uUtils.getInteger(pos.trackid);
|
||||
position.timestamp = uUtils.getInteger(pos.timestamp);
|
||||
position.distance = uUtils.getInteger(pos.distance);
|
||||
position.meters = uUtils.getInteger(pos.meters);
|
||||
position.seconds = uUtils.getInteger(pos.seconds);
|
||||
position.totalDistance = 0;
|
||||
position.totalMeters = 0;
|
||||
position.totalSeconds = 0;
|
||||
return position;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ describe('Ajax tests', () => {
|
||||
expect(result).toEqual(validResponse);
|
||||
done();
|
||||
})
|
||||
.catch(() => done.fail('reject callback called'));
|
||||
.catch((e) => done.fail(`reject callback called (${e})`));
|
||||
});
|
||||
|
||||
it('should make successful request and return error with message', (done) => {
|
||||
|
@ -34,7 +34,7 @@ describe('Observe tests', () => {
|
||||
describe('when object is observed', () => {
|
||||
|
||||
it('should throw error if observer is missing', () => {
|
||||
expect(() => { uObserve.observe(object, 'observed'); }).toThrow(new Error('Invalid arguments'));
|
||||
expect(() => { uObserve.observe(object, 'observed'); }).toThrow(new Error('Invalid argument for observe'));
|
||||
});
|
||||
|
||||
it('should notify observers when observed property is modified', () => {
|
||||
@ -181,7 +181,7 @@ describe('Observe tests', () => {
|
||||
it('should throw error if removed observer is missing', () => {
|
||||
expect(() => {
|
||||
uObserve.unobserve(object, 'unobserved');
|
||||
}).toThrow(new Error('Invalid arguments'));
|
||||
}).toThrow(new Error('Invalid argument for unobserve'));
|
||||
});
|
||||
|
||||
it('should not notify observers when unobserved property is modified', () => {
|
||||
|
@ -38,7 +38,7 @@ describe('Position tests', () => {
|
||||
'username',
|
||||
'trackid',
|
||||
'trackname',
|
||||
'distance',
|
||||
'meters',
|
||||
'seconds'
|
||||
];
|
||||
const properties = nullableProperties.concat(nonNullableProperties);
|
||||
@ -57,7 +57,7 @@ describe('Position tests', () => {
|
||||
let username;
|
||||
let trackid;
|
||||
let trackname;
|
||||
let distance;
|
||||
let meters;
|
||||
let seconds;
|
||||
|
||||
let jsonPosition;
|
||||
@ -77,7 +77,7 @@ describe('Position tests', () => {
|
||||
username = 'test';
|
||||
trackid = 134;
|
||||
trackname = 'Test name';
|
||||
distance = 0;
|
||||
meters = 0;
|
||||
seconds = 0;
|
||||
|
||||
jsonPosition = {
|
||||
@ -95,7 +95,7 @@ describe('Position tests', () => {
|
||||
'username': username,
|
||||
'trackid': trackid,
|
||||
'trackname': trackname,
|
||||
'distance': distance,
|
||||
'meters': meters,
|
||||
'seconds': seconds
|
||||
};
|
||||
});
|
||||
@ -117,7 +117,7 @@ describe('Position tests', () => {
|
||||
expect(position.username).toBe(username);
|
||||
expect(position.trackid).toBe(trackid);
|
||||
expect(position.trackname).toBe(trackname);
|
||||
expect(position.distance).toBe(distance);
|
||||
expect(position.meters).toBe(meters);
|
||||
expect(position.seconds).toBe(seconds);
|
||||
});
|
||||
|
||||
@ -129,7 +129,7 @@ describe('Position tests', () => {
|
||||
// when
|
||||
delete posCopy[prop];
|
||||
// then
|
||||
expect(() => { uPosition.fromJson(posCopy); }).toThrow(new Error('Illegal value'));
|
||||
expect(() => { uPosition.fromJson(posCopy); }).toThrow(new Error('Invalid value'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -142,7 +142,7 @@ describe('Position tests', () => {
|
||||
// when
|
||||
posCopy[prop] = null;
|
||||
// then
|
||||
expect(() => { uPosition.fromJson(posCopy); }).toThrow(new Error('Illegal value'));
|
||||
expect(() => { uPosition.fromJson(posCopy); }).toThrow(new Error('Invalid value'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -156,7 +156,7 @@ describe('Position tests', () => {
|
||||
posCopy[prop] = null;
|
||||
let pos = {};
|
||||
// then
|
||||
expect(() => { pos = uPosition.fromJson(posCopy); }).not.toThrow(new Error('Illegal value'));
|
||||
expect(() => { pos = uPosition.fromJson(posCopy); }).not.toThrow(new Error('Invalid value'));
|
||||
expect(pos[prop]).toBeNull();
|
||||
});
|
||||
});
|
||||
|
@ -60,6 +60,7 @@ describe('User tests', () => {
|
||||
|
||||
describe('ajax tests', () => {
|
||||
const validResponse = [ { 'id': 1, 'login': 'test' }, { 'id': 2, 'login': 'test2' }, { 'id': 18, 'login': 'demo' } ];
|
||||
const invalidResponse = [ { 'login': 'test' }, { 'id': 2, 'login': 'test2' }, { 'id': 18, 'login': 'demo' } ];
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(XMLHttpRequest.prototype, 'open').and.callThrough();
|
||||
@ -75,11 +76,26 @@ describe('User tests', () => {
|
||||
// then
|
||||
uUser.fetchList()
|
||||
.then((result) => {
|
||||
expect(XMLHttpRequest.prototype.open).toHaveBeenCalledWith('GET', 'utils/getusers.php', true);
|
||||
expect(result).toEqual(jasmine.arrayContaining([ new uUser(1, 'test') ]));
|
||||
expect(result.length).toBe(3);
|
||||
done();
|
||||
})
|
||||
.catch(() => done.fail('reject callback called'));
|
||||
.catch((e) => done.fail(`reject callback called (${e})`));
|
||||
});
|
||||
|
||||
it('should throw error on invalid data in JSON', (done) => {
|
||||
// when
|
||||
spyOnProperty(XMLHttpRequest.prototype, 'responseText').and.returnValue(JSON.stringify(invalidResponse));
|
||||
// then
|
||||
uUser.fetchList()
|
||||
.then(() => {
|
||||
done.fail('resolve callback called');
|
||||
})
|
||||
.catch((e) => {
|
||||
expect(e).toEqual(jasmine.any(Error));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user