diff --git a/Response.js b/Response.js index a611cb6..9a3fcfc 100644 --- a/Response.js +++ b/Response.js @@ -1139,9 +1139,7 @@ Queue.prototype.stop = function () { * @returns {Queue} */ Queue.prototype.push = function (item, name) { - var keyIndex = this.items.length + this.stateData.length + Number(this.isStarted); - - this.keys[keyIndex] = arguments.length > 1 || item == null ? name : item.name; + this.keys.push(arguments.length > 1 || item == null ? name : item.name); this.items.push(item); return this; diff --git a/package.json b/package.json index ce3ea7a..de407d6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "Response", "author": "Vladislav Kurkin (https://github.com/B-Vladi)", - "version": "0.1.3", + "version": "0.1.4", "main": "Response.js", "license": "MIT", "repository": { diff --git a/spec/Queue.spec.js b/spec/Queue.spec.js index 6fa80ef..5a16c40 100644 --- a/spec/Queue.spec.js +++ b/spec/Queue.spec.js @@ -262,9 +262,31 @@ describe('Queue:', function () { expect(queue.items).toEqual([i0, i1, i2, i2, i3, i3]); }); - it('dynamic push in items', function () { + it('order of the keys by dynamic addition', function () { + var q = new Queue(); + queue = new Queue() - .push({ + .push(1, 'a') + .push(function b () { + expect(this.keys).toEqual(['a', 'b', 'c']); + + this.push(q, 'd'); + + expect(this.keys).toEqual(['a', 'b', 'c', 'd']); + expect(this.keys.length).toBe(4); + + return q; + }) + .push(3, 'c') + .start(); + + q.resolve(); + + expect(queue.keys).toEqual(['a', 'b', 'c', 'd']); + }); + + it('dynamic push in items', function () { + queue = new Queue({ name: 'key0' }) .push(function key1 () {