UNPKG

ck-array

Version:

A simple observable array for JavaScript Frameworks

105 lines (102 loc) 3.75 kB
// Generated by CoffeeScript 1.9.1 (function() { describe('A test suite for the CkArray class', function() { var a; a = void 0; it('should be able to be required', function() { var CkArray; CkArray = require('./../src/CkArray'); expect(CkArray).not.toBeNull(); return expect(CkArray).not.toBeUndefined(); }); it('should be able to create an Array which acts like an Array', function() { var CkArray; CkArray = require('./../src/CkArray'); a = new CkArray(); expect(a).not.toBeNull(); expect(a).not.toBeUndefined(); return expect(a instanceof Array).toMatch(/true/); }); it('should be able to initialize from array', function() { var CkArray, testArray; CkArray = require('./../src/CkArray'); testArray = new CkArray([1, 2, 3, 4, 5, 6, 7, 8, 9]); return expect(testArray.length).toEqual(9); }); it('should have a length property', function() { expect(a.length).toBeDefined(); return expect(a.length).toEqual(0); }); it('should have a push function which pushes an item onto the array and increments the length property by one', function() { expect(a.push).toBeDefined('CkArray does not have a push method'); expect(typeof a.push).toEqual('function', 'The push method on the CkArray is not a function'); return expect(a.push(12)).toEqual(1); }); it('should be able to observe changes and handle push messages', function() { var postItem, preItem; expect(a.observe).toBeDefined('CkArray does not have a pushObserve member'); expect(typeof a.observe).toEqual('function', 'The pushObserve member of CkArray is not a function'); preItem = void 0; postItem = void 0; a.observe({ prePush: function(item) { return preItem = item; }, postPush: function(item) { return postItem = item; } }); a.push(13); expect(preItem).toEqual(13); return expect(postItem).toEqual(13); }); it('should be able to observe changes from slice', function() { var CkArray, postSlice, preSlice; CkArray = require('./../src/CkArray'); a = new CkArray(); [1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(function(n) { return a.push(n); }); preSlice = void 0; postSlice = void 0; a.observe({ preSlice: function() { return preSlice = {}; }, postSlice: function(items) { return postSlice = items; } }); a.slice(4, 6); expect(preSlice).not.toBeUndefined(); expect(postSlice).not.toBeUndefined(); expect(postSlice instanceof Array).toMatch(/true/); return expect(postSlice.length).toEqual(2, 'length is not correct'); }); return it('should be able to observe changes from splice', function() { var CkArray, postSplice, preSplice; CkArray = require('./../src/CkArray'); a = new CkArray(); [1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(function(n) { return a.push(n); }); preSplice = void 0; postSplice = void 0; a.observe({ preSplice: function() { return preSplice = {}; }, postSplice: function(items) { return postSplice = items; } }); a.splice(4, 3); expect(preSplice).not.toBeUndefined(); expect(postSplice).not.toBeUndefined(); expect(postSplice instanceof Array).toMatch(/true/); expect(postSplice.length).toEqual(3, 'length is not correct'); return expect(a.length).toEqual(6, 'the original array is not modified, it\'s length should be 6'); }); }); }).call(this); //# sourceMappingURL=ckArray.spec.js.map