Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 716e30d

Browse files
committed
UtilityService spec test works!
1 parent 2fb4e14 commit 716e30d

File tree

2 files changed

+84
-9
lines changed

2 files changed

+84
-9
lines changed

test/runner.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,19 @@
1212
<script src="unit/servicesSpec.js"></script>
1313
</head>
1414
<body>
15+
<script>
16+
17+
// KICK OFF JASMINE
18+
var jasmineEnv = jasmine.getEnv();
19+
var trivialReporter = new jasmine.TrivialReporter();
20+
21+
jasmineEnv.addReporter(trivialReporter);
22+
23+
jasmineEnv.specFilter = function(spec) {
24+
return trivialReporter.specFilter(spec);
25+
};
26+
27+
jasmineEnv.execute();
28+
</script>
1529
</body>
1630
</html>

test/unit/servicesSpec.js

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,78 @@
22

33
/* jasmine specs for services go here */
44

5-
describe('Utility Service', function() {
6-
describe('evalProperty should find the right property given a heirarchy', function() {
7-
var service;
8-
beforeEach(module('ngGrid.services'));
9-
beforeEach(inject(function($utilityService) {
10-
service = $utilityService;
11-
}));
12-
13-
it('returns "foundme"', function() {
5+
describe('Utility Service', function () {
6+
var service;
7+
beforeEach(module('ngGrid.services'));
8+
beforeEach(inject(function ($utilityService) {
9+
service = $utilityService;
10+
}));
11+
// evalProperty
12+
describe('evalProperty should find the right property given a heirarchy.', function () {
13+
// foundme
14+
it('returns foundme', function() {
1415
var obj = { foo: { bar: { hello: { world: "foundme" } } } };
1516
expect(service.evalProperty(obj, "foo.bar.hello.world")).toEqual("foundme");
1617
});
18+
// undefined
19+
it('returns undefined', function () {
20+
var obj = { foo: { bar: { hello: { world: "foundme" } } } };
21+
expect(service.evalProperty(obj, "foo.bar.omg")).toEqual(undefined);
22+
});
23+
});
24+
// visualLength
25+
describe('visualLength should return the correct visual length of text.', function () {
26+
it('returns integer', function() {
27+
var node = angular.element('<div style="width: 30px;">The quick brown fox jumped over the lazy dog.</div>');
28+
expect(service.visualLength(node)).toEqual(298);
29+
});
30+
});
31+
// forIn
32+
describe('forIn should execute the function for each key in an object.', function() {
33+
it('executes some code', function () {
34+
var obj = {
35+
foo: "foo",
36+
bar: "bar",
37+
hello: "hello",
38+
world: "world"
39+
};
40+
41+
service.forIn(obj, function(val, key) {
42+
obj[key] = "foundme";
43+
});
44+
expect(obj.foo).toEqual("foundme");
45+
expect(obj.bar).toEqual("foundme");
46+
expect(obj.hello).toEqual("foundme");
47+
expect(obj.world).toEqual("foundme");
48+
});
49+
});
50+
// endsWith
51+
describe('endsWith should return true or false based on the last character in a string', function () {
52+
var str = "Peter Piper picked a peck of pickeled peppers";
53+
it('returns true', function() {
54+
55+
expect(service.endsWith(str, "peppers")).toEqual(true);
56+
});
57+
it('returns false', function () {
58+
expect(service.endsWith(str, "peter")).toEqual(false);
59+
});
60+
});
61+
// isNullOrUndefined
62+
describe('isNullOrUndefined return true or false based on wherer or not a given reference is explucitly null or undefined', function () {
63+
it('returns true', function () {
64+
var hello;
65+
expect(service.isNullOrUndefined(hello)).toEqual(true);
66+
var hello = null;
67+
expect(service.isNullOrUndefined(hello)).toEqual(true);
68+
var hello = undefined;
69+
expect(service.isNullOrUndefined(hello)).toEqual(true);
70+
expect(service.isNullOrUndefined(null)).toEqual(true);
71+
expect(service.isNullOrUndefined(undefined)).toEqual(true);
72+
});
73+
it('returns false', function () {
74+
expect(service.isNullOrUndefined("foundme")).toEqual(false);
75+
expect(service.isNullOrUndefined("")).toEqual(false);
76+
expect(service.isNullOrUndefined(0)).toEqual(false);
77+
});
1778
});
1879
});

0 commit comments

Comments
 (0)