Files
scratch-gui/test/unit/util/cloud-provider.test.js
T
Paul Kaplan e453fe2c00 Fix problem with updating cloud vars to zero.
Added a unit test and covered the other case (not used) where you might be trying to update the index zero of a list
2018-11-05 15:17:40 -05:00

45 lines
1.3 KiB
JavaScript

import CloudProvider from '../../../src/lib/cloud-provider';
// Disable window.WebSocket
global.WebSocket = null;
describe('CloudProvider', () => {
let cloudProvider = null;
let sentMessage = null;
beforeEach(() => {
cloudProvider = new CloudProvider();
// Stub connection
cloudProvider.connection = {
send: msg => {
sentMessage = msg;
}
};
});
test('updateVariable', () => {
cloudProvider.updateVariable('hello', 1);
const obj = JSON.parse(sentMessage);
expect(obj.method).toEqual('set');
expect(obj.name).toEqual('hello');
expect(obj.value).toEqual(1);
});
test('updateVariable with falsey value', () => {
cloudProvider.updateVariable('hello', 0);
const obj = JSON.parse(sentMessage);
expect(obj.method).toEqual('set');
expect(obj.name).toEqual('hello');
expect(obj.value).toEqual(0);
});
test('writeToServer with falsey index value', () => {
cloudProvider.writeToServer('method', 'name', 5, 0);
const obj = JSON.parse(sentMessage);
expect(obj.method).toEqual('method');
expect(obj.name).toEqual('name');
expect(obj.value).toEqual(5);
expect(obj.index).toEqual(0);
});
});