Skip to content

Commit fbf3c0a

Browse files
author
Philipp Alferov
committed
Refine tests
1 parent 9337233 commit fbf3c0a

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

test/angular-file-saver-bundle.spec.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,48 @@ describe('angular-file-saver', function() {
55
var FileSaver, Blob;
66

77
beforeEach(function() {
8-
98
angular.mock.module('ngFileSaver');
10-
119
angular.mock.inject(function(_FileSaver_, _Blob_) {
1210
FileSaver = _FileSaver_;
1311
Blob = _Blob_;
1412
});
1513
});
1614

17-
describe('passed arguments are correct', function() {
15+
describe('#saveAs', function() {
1816

19-
it('should throw an error if provided data is an array', function() {
17+
it('should throw an error if `options.data` is not a blob', function() {
2018
var config = {
2119
data: ['text'],
2220
filename: 'xfiles.txt'
2321
};
22+
expect(function() { FileSaver.saveAs(config); })
23+
.toThrowError(/should be a blob instance/);
24+
});
2425

25-
expect(function() { FileSaver.saveAs(config); }).toThrow();
26+
it('should throw an error if `options` object is empty', function() {
27+
var config = {};
28+
expect(function() { FileSaver.saveAs(config); })
29+
.toThrowError(/should be a blob instance/);
2630
});
2731

28-
it('should save a file if provided data is a blob', function() {
32+
it('should throw an error if `options` object is not passed', function() {
33+
expect(function() { FileSaver.saveAs(); })
34+
.toThrowError(/should be a blob instance/);
35+
});
36+
37+
it('should throw an error if `options.filename` is not a string', function() {
2938
var data = new Blob(['text'], { type: 'text/plain;charset=utf-8' });
39+
var config = {
40+
data: data,
41+
filename: null
42+
};
43+
44+
expect(function() { FileSaver.saveAs(config); })
45+
.toThrowError(/should be a string/);
46+
});
3047

48+
it('should save a file if provided data is valid', function() {
49+
var data = new Blob(['text'], { type: 'text/plain;charset=utf-8' });
3150
var config = {
3251
data: data,
3352
filename: 'xfiles.txt'
@@ -37,4 +56,5 @@ describe('angular-file-saver', function() {
3756
});
3857

3958
});
59+
4060
});

0 commit comments

Comments
 (0)