Skip to content

Commit 070361c

Browse files
authored
Merge pull request #1 from ravenscar/add-tests
Add tests
2 parents 468e495 + 1163187 commit 070361c

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
"grunt-contrib-uglify": "",
1111
"grunt-notify": "",
1212
"grunt-strip": "",
13-
"grunt-text-replace": ""
13+
"grunt-text-replace": "",
14+
"tape": "^4.6.3"
1415
},
1516
"name": "@ninjatronic/angular-base64",
1617
"description": "Encapsulation of Nick Galbreath's base64.js library for AngularJS",
1718
"version": "0.0.2",
1819
"main": "index.js",
1920
"scripts": {
20-
"test": "echo \"Error: no test specified\" && exit 1"
21+
"test": "node tests"
2122
},
2223
"repository": {
2324
"type": "git",

tests.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var test = require('tape');
2+
3+
var constants = {};
4+
5+
global.angular = {
6+
module: function (moduleName, deps) {
7+
return {
8+
constant: function (constantName, value) { constants[constantName] = value; }
9+
}
10+
}
11+
}
12+
13+
var b64 = require('./angular-base64.js');
14+
15+
test('constant registered', function (t) {
16+
t.plan(1);
17+
18+
t.notEqual(undefined, constants.$base64);
19+
})
20+
21+
test('can encode and decode non-padded', function (t) {
22+
t.plan(2);
23+
24+
var text = "The quick brown fox jumps over the lazy doges";
25+
var b64 = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZ2Vz";
26+
27+
t.equal(b64, constants.$base64.encode(text));
28+
t.equal(text, constants.$base64.decode(b64));
29+
})
30+
31+
test('can encode and decode padded', function (t) {
32+
t.plan(2);
33+
34+
var text = "The quick brown fox jumps over the lazy dog";
35+
var b64 = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==";
36+
37+
console.log(constants.$base64.encode(text))
38+
39+
t.equal(b64, constants.$base64.encode(text));
40+
t.equal(text, constants.$base64.decode(b64));
41+
})
42+
43+
test('can decode with padding missing', function (t) {
44+
t.plan(1);
45+
46+
var text = "The quick brown fox jumps over the lazy dog";
47+
var b64 = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw";
48+
49+
t.equal(text, constants.$base64.decode(b64));
50+
})

0 commit comments

Comments
 (0)