diff options
author | 2023-03-07 21:56:21 -0800 | |
---|---|---|
committer | 2023-03-07 21:56:21 -0800 | |
commit | 4d3eefa45f0c5adcb278a81f6f536227ffac9550 (patch) | |
tree | 913742e104a25da57410acc54fb3cc8592f0fe2a | |
parent | 7a748678ae29b19db7f0b0a8f070d6432f54e5f9 (diff) | |
download | bun-4d3eefa45f0c5adcb278a81f6f536227ffac9550.tar.gz bun-4d3eefa45f0c5adcb278a81f6f536227ffac9550.tar.zst bun-4d3eefa45f0c5adcb278a81f6f536227ffac9550.zip |
More tests for blob.slice
-rw-r--r-- | packages/bun-types/globals.d.ts | 24 | ||||
-rw-r--r-- | test/js/web/fetch/blob.test.ts | 14 |
2 files changed, 37 insertions, 1 deletions
diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts index 2dd86f911..aab4921bd 100644 --- a/packages/bun-types/globals.d.ts +++ b/packages/bun-types/globals.d.ts @@ -565,7 +565,29 @@ declare class Blob implements BlobInterface { * @param end The index that sets the end of the view. * */ - slice(begin?: number, end?: number): Blob; + slice(begin?: number, end?: number, contentType?: string): Blob; + + /** + * Create a new view **without 🚫 copying** the underlying data. + * + * Similar to [`BufferSource.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BufferSource/subarray) + * + * @param begin The index that sets the beginning of the view. + * @param end The index that sets the end of the view. + * + */ + slice(begin?: number, contentType?: string): Blob; + + /** + * Create a new view **without 🚫 copying** the underlying data. + * + * Similar to [`BufferSource.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BufferSource/subarray) + * + * @param begin The index that sets the beginning of the view. + * @param end The index that sets the end of the view. + * + */ + slice(contentType?: string): Blob; /** * Read the data from the blob as a string. It will be decoded from UTF-8. diff --git a/test/js/web/fetch/blob.test.ts b/test/js/web/fetch/blob.test.ts index b5a256671..ba44f8c1b 100644 --- a/test/js/web/fetch/blob.test.ts +++ b/test/js/web/fetch/blob.test.ts @@ -12,6 +12,20 @@ test("Blob.slice", () => { expect(b3.size).toBe(0); const b4 = blob.slice(0, 10); expect(b4.size).toBe(blob.size); + + expect(blob.slice().size).toBe(blob.size); + expect(blob.slice(0).size).toBe(blob.size); + expect(blob.slice(NaN).size).toBe(blob.size); + expect(blob.slice(0, Infinity).size).toBe(blob.size); + expect(blob.slice(-Infinity).size).toBe(blob.size); + expect(blob.slice(0, NaN).size).toBe(0); + // @ts-expect-error + expect(blob.slice(Symbol(), "-123").size).toBe(6); + expect(blob.slice(Object.create(null), "-123").size).toBe(6); + // @ts-expect-error + expect(blob.slice(null, "-123").size).toBe(6); + expect(blob.slice(0, 10).size).toBe(blob.size); + expect(blob.slice("text/plain;charset=utf-8").type).toBe("text/plain;charset=utf-8"); }); test("new Blob", () => { |