|
2 | 2 |
|
3 | 3 | /* jasmine specs for services go here */
|
4 | 4 |
|
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() { |
14 | 15 | var obj = { foo: { bar: { hello: { world: "foundme" } } } };
|
15 | 16 | expect(service.evalProperty(obj, "foo.bar.hello.world")).toEqual("foundme");
|
16 | 17 | });
|
| 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 | + }); |
17 | 78 | });
|
18 | 79 | });
|
0 commit comments