|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -describe('Angular', function() { |
| 3 | +describe('angular-file-saver', function() { |
4 | 4 |
|
5 | | - it('should exist', function() { |
6 | | - expect(angular).toBeDefined(); |
| 5 | + var SaveAs, $window, Blob, options, filename; |
| 6 | + beforeEach(module('fileSaver')); |
| 7 | + |
| 8 | + beforeEach(inject(function(_SaveAs_, _$window_) { |
| 9 | + SaveAs = _SaveAs_; |
| 10 | + $window = _$window_; |
| 11 | + Blob = $window.Blob; |
| 12 | + })); |
| 13 | + |
| 14 | + it('should not throw an error if dependencies are defined', function() { |
| 15 | + expect($window.saveAs).toBeDefined(); |
| 16 | + expect($window.Blob).toBeDefined(); |
7 | 17 | }); |
8 | 18 |
|
| 19 | + describe('passed arguments are correct', function() { |
| 20 | + |
| 21 | + beforeEach(function() { |
| 22 | + options = { type: 'text/plain;charset=utf-8' }; |
| 23 | + filename = 'xfiles.txt'; |
| 24 | + }); |
| 25 | + |
| 26 | + it('should save a file if provided data is an array', function() { |
| 27 | + var data = ['text']; |
| 28 | + |
| 29 | + expect(function() { |
| 30 | + SaveAs.download(data, filename, options); |
| 31 | + }).not.toThrow(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should save a file if provided data is a blob', function() { |
| 35 | + var data = new Blob(['text'], options); |
| 36 | + console.log(data instanceof Blob); |
| 37 | + expect(function() { |
| 38 | + SaveAs.download(data, filename); |
| 39 | + }).not.toThrow(); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should save a file if options object is not passed', function() { |
| 43 | + var data = ['text']; |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + expect(function() { |
| 48 | + SaveAs.download(data, filename); |
| 49 | + }).not.toThrow(); |
| 50 | + }); |
| 51 | + |
| 52 | + }); |
9 | 53 | }); |
0 commit comments