Skip to content

Commit

Permalink
added more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
craigmaslowski committed Nov 23, 2011
1 parent 227f5f0 commit 3dd79e1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
6 changes: 5 additions & 1 deletion test/spec/CacheWithDefaultsSpec.js
Expand Up @@ -16,6 +16,10 @@ describe('a cache with defaults', function () {
});

it('should reset the cache to defaults when calling reset', function () {
cacheWithDefaults.get('#elcacheo')
expect(cacheWithDefaults.cache['#elcacheo']).toBeDefined();
cacheWithDefaults.unset('#elcacheo');
expect(cacheWithDefaults.cache['#elcacheo']).toBeUndefined();
cacheWithDefaults.reset();
expect(cacheWithDefaults.cache['#elcacheo']).toBeDefined();
});
});
34 changes: 34 additions & 0 deletions test/spec/CacheWithInitializationSpec.js
@@ -0,0 +1,34 @@
var CacheWithInitialization = ElCacheo.Cache.extend({
initialize: function (cache, options) {
this.passedInCache = cache;
this.passedInOptions = options;
}
});

var initialCache = {
'body': $('body')
};

var initialOptions = {
someOption: "someOption's value"
};

var cacheWithInitialization = new CacheWithInitialization(initialCache, initialOptions);

describe('a cache with initialization', function () {
it('should have a passedInCache property', function () {
expect(cacheWithInitialization.passedInCache).toBeDefined();
});

it('should have a passedInCache property equal to initialCache', function () {
expect(cacheWithInitialization.passedInCache).toEqual(initialCache);
});

it('should have a passedInOptions property', function () {
expect(cacheWithInitialization.passedInOptions).toBeDefined();
});

it('should have a passedInOptions property equal to initialOptions', function () {
expect(cacheWithInitialization.passedInOptions).toEqual(initialOptions);
});
});
10 changes: 0 additions & 10 deletions test/spec/SpecHelper.js
@@ -1,15 +1,5 @@
beforeEach(function() {
this.addMatchers({
toBeCached: function(selector) {
var cache = this.actual;
return cache.cache[selector] != null;
},

toNotBeCached: function(selector) {
var cache = this.actual;
return cache.cache[selector] == null;
},

toBeAFunction: function() {
return _.isFunction(this.actual);
},
Expand Down
1 change: 1 addition & 0 deletions test/specrunner.html
Expand Up @@ -15,6 +15,7 @@
<script src="spec/SpecHelper.js"></script>
<script src="spec/ElCacheoSpec.js"></script>
<script src="spec/CacheWithDefaultsSpec.js"></script>
<script src="spec/CacheWithInitializationSpec.js"></script>

<script>
(function() {
Expand Down

0 comments on commit 3dd79e1

Please sign in to comment.