Skip to content

Commit 1afa8a1

Browse files
author
Philipp Alferov
committed
Add basic test cases
1 parent f80a87b commit 1afa8a1

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

test/angular-file-saver.spec.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
11
'use strict';
22

3-
describe('Angular', function() {
3+
describe('angular-file-saver', function() {
44

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();
717
});
818

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+
});
953
});

test/karma.conf.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function(config) {
99
},
1010
browsers: ['Chrome'],
1111
reporters: ['progress'],
12-
autoWatch: true,
12+
autoWatch: false,
1313
browserify: {
1414
debug: true,
1515
transform: []
@@ -18,7 +18,10 @@ module.exports = function(config) {
1818
'/': 'http://localhost:9876/'
1919
},
2020
urlRoot: '/__karma__/',
21+
singleRun: true,
2122
files: [
23+
'./node_modules/Blob.js/Blob.js',
24+
'./node_modules/FileSaver.js/FileSaver.js',
2225
'./node_modules/angular/angular.js',
2326
'./node_modules/angular-mocks/angular-mocks.js',
2427
'./src/angular-file-saver.js',

0 commit comments

Comments
 (0)