@@ -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 ( / s h o u l d b e a b l o b i n s t a n c e / ) ;
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 ( / s h o u l d b e a b l o b i n s t a n c e / ) ;
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 ( / s h o u l d b e a b l o b i n s t a n c e / ) ;
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 ( / s h o u l d b e a s t r i n g / ) ;
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