throw simpler errors on some invalid inputs
[squeep-mystery-box] / test / lib / mystery-box.js
index 8d228e6e25d4a5044b99bb889036f7be38a93d48..a6e69b91f25ae0553dee526649e9ae51e103ef14 100644 (file)
@@ -161,6 +161,26 @@ describe('MysteryBox', function () {
       const decryptedResult = await mb.unpack(encryptedResult);
       assert.deepStrictEqual(decryptedResult, object);
     });
+
+    it('handles undefined', async function () {
+      try {
+        await mb.unpack();
+        assert.fail(noExpectedException);
+      } catch (e) {
+        assert(e instanceof RangeError, noExpectedException);
+      }
+    });
+
+    it('handles incomplete', async function () {
+      const encryptedResult = await mb.pack({ foo: 'bar' });
+      try {
+        await mb.unpack(encryptedResult.slice(0, 6));
+        assert.fail(noExpectedException);
+      } catch (e) {
+        assert(e instanceof RangeError, noExpectedException);
+      }
+    });
+
   }); // pack, unpack
 
 }); // MysteryBox
\ No newline at end of file