diff --git a/test/jio/tests.js b/test/jio/tests.js index ff308f33a6e99d651938f7bd5eec7221226a7a1a..17666abe38f20a5c5fd5980b7243169e4a8e54e3 100644 --- a/test/jio/tests.js +++ b/test/jio/tests.js @@ -140,6 +140,44 @@ deepEqual(result, "No error thrown", "Good parameter"); }); + /** + * Tests asynchrony + */ + test("Asynchrony", function () { + var workspace = {}, clock, jio, count = 0; + expect(8); + + clock = sinon.useFakeTimers(); + jio = new JIO({ + "type": "fake", + "id": "Asynchrony" + }, { + "workspace": workspace + }); + + jio.post({}).done(function () { + count += 1; + deepEqual(count, 6, "Command done"); + }).progress(function () { + count += 1; + deepEqual(count, 3, "Command notifiy"); + }); + count += 1; + deepEqual(count, 1, "JIO post"); + ok(!fakestorage['Asynchrony/post'], "Command not called yet"); + clock.tick(1); + count += 1; + deepEqual(count, 2, "Next instructions"); + ok(fakestorage['Asynchrony/post'], "Command called"); + fakestorage['Asynchrony/post'].notify(); + count += 1; + deepEqual(count, 4, "Next timer"); + fakestorage['Asynchrony/post'].success({"id": "a"}); + count += 1; + deepEqual(count, 5, "Command success requested"); + clock.tick(1); + }); + /** * Tests a storage initialization error */