Add test for complex object

This commit is contained in:
Ian Gulliver
2014-05-15 19:23:21 +03:00
parent 92be7e7b28
commit 179fad1c96

View File

@@ -25,9 +25,6 @@ server interactions are complex and tests should be structured to verify them,
not to verify the behavior of a simulation. not to verify the behavior of a simulation.
*/ */
QUnit.begin(localStorage.clear.bind(localStorage));
QUnit.done(localStorage.clear.bind(localStorage));
var randstring = function() { var randstring = function() {
var ret = []; var ret = [];
for (var i = 0; i < 16; i++) { for (var i = 0; i < 16; i++) {
@@ -37,6 +34,11 @@ var randstring = function() {
return ret.join(''); return ret.join('');
}; };
QUnit.begin(localStorage.clear.bind(localStorage));
QUnit.done(localStorage.clear.bind(localStorage));
module('General');
test('Construct/shutdown', function() { test('Construct/shutdown', function() {
expect(2); expect(2);
var cosmo = new Cosmopolite({}); var cosmo = new Cosmopolite({});
@@ -140,3 +142,41 @@ asyncTest('Overwrite key', function() {
var cosmo1 = new Cosmopolite(callbacks1, null, randstring()); var cosmo1 = new Cosmopolite(callbacks1, null, randstring());
var cosmo2 = new Cosmopolite(callbacks2, null, randstring()); var cosmo2 = new Cosmopolite(callbacks2, null, randstring());
}); });
asyncTest('Complex object', function() {
expect(2);
var subject = randstring();
var message = {
'foo': 'bar',
5: 'zig',
'zag': [16, 22, 59, 76],
'boo': {
'nested': 'object',
10: 100,
},
'unicode': '☠☣☃𠜎',
};
var callbacks1 = {
'onReady': function() {
cosmo1.sendMessage(subject, message);
},
};
var callbacks2 = {
'onReady': function() {
cosmo2.subscribe(subject, -1);
},
'onMessage': function(e) {
equal(e['subject'], subject, 'subject matches');
deepEqual(e['message'], message, 'message matches');
cosmo1.shutdown();
cosmo2.shutdown();
start();
},
};
var cosmo1 = new Cosmopolite(callbacks1, null, randstring());
var cosmo2 = new Cosmopolite(callbacks2, null, randstring());
});