DefinitelyTyped/types/file-saver/file-saver-tests.ts
Hitko Development 283d30a07a Deprecate disableAutoBOM as per file-saver 2.0 (#35617)
* Deprecate `disableAutoBOM` as per FileSaver 2.0

* Lint rules
2019-05-21 12:53:24 -07:00

69 lines
1.8 KiB
TypeScript

import { FileSaverOptions } from "file-saver";
/**
* @summary Test for "saveAs" function.
*/
function testSaveAs() {
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
const filename = 'hello world.txt';
const options: FileSaverOptions = {
autoBom: false
};
saveAs(data, filename, options);
}
/**
* @summary Test for deprecated "saveAs" function.
*/
function testDeprecatedSaveAs() {
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
const filename = 'hello world.txt';
const disableAutoBOM = true;
saveAs(data, filename, disableAutoBOM);
}
/**
* @summary Test for "saveAs" function on the window object.
*/
function testWindowSaveAs() {
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
const filename = 'hello world.txt';
const options: FileSaverOptions = {
autoBom: false
};
window.saveAs(data, filename, options);
}
/**
* @summary Test for "saveAs" function with URL as first argument.
*/
function testUrlSaveAs() {
const url = 'https://example.com/test.txt';
const filename = 'hello world.txt';
const options: FileSaverOptions = {
autoBom: false
};
window.saveAs(url, filename, options);
}
/**
* @summary Test for "saveAs" function with the 3rd parameter omitted
*/
function testOptionalOneParamSaveAs() {
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
const filename = 'hello world.txt';
saveAs(data, filename);
}
/**
* @summary Test for "saveAs" function with the 2nd and 3rd parameters omitted
*/
function testOptionalTwoParamsSaveAs() {
const data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
saveAs(data);
}