diff options
author | 2023-01-10 18:48:55 -0800 | |
---|---|---|
committer | 2023-01-10 18:49:26 -0800 | |
commit | bcabf31121f4fff4e124bfbe11588fe9f1711e07 (patch) | |
tree | 12773549541786e4f65e7df6f3611ddad7b2e529 /test | |
parent | 5cb6890fad1e6d49f51f3571278cb32554fbe459 (diff) | |
download | bun-bcabf31121f4fff4e124bfbe11588fe9f1711e07.tar.gz bun-bcabf31121f4fff4e124bfbe11588fe9f1711e07.tar.zst bun-bcabf31121f4fff4e124bfbe11588fe9f1711e07.zip |
Make `Buffer` mockable
Diffstat (limited to 'test')
-rw-r--r-- | test/bun.js/buffer.test.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/bun.js/buffer.test.js b/test/bun.js/buffer.test.js index 4c8603335..d263a80eb 100644 --- a/test/bun.js/buffer.test.js +++ b/test/bun.js/buffer.test.js @@ -673,3 +673,28 @@ it("Buffer.toString(base64)", () => { ); } }); + +it("Buffer can be mocked", () => { + function MockBuffer() { + const noop = function () {}; + const res = Buffer.alloc(0); + for (const op in Buffer.prototype) { + if (typeof res[op] === "function") { + res[op] = noop; + } + } + return res; + } + + const buf = MockBuffer(); + + expect(() => { + buf.write("hello world"); + buf.writeUint16BE(0); + buf.writeUint32BE(0); + buf.writeBigInt64BE(0); + buf.writeBigUInt64BE(0); + buf.writeBigInt64LE(0); + buf.writeBigUInt64LE(0); + }).not.toThrow(); +}); |