diff --git a/.gitignore b/.gitignore index da23d0d..44e4d24 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ build/Release # Deployed apps should consider commenting this line out: # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git node_modules + +package-lock.json \ No newline at end of file diff --git a/package.json b/package.json index 7d46b91..225d262 100644 --- a/package.json +++ b/package.json @@ -26,12 +26,12 @@ }, "homepage": "https://github.com/ahmednuaman/javascript-tests", "dependencies": { - "karma": "^0.12.32", - "karma-jasmine": "^0.3.5", - "karma-phantomjs-launcher": "^0.1.4" + "karma": "^5.1.0", + "karma-jasmine": "^3.3.1", + "karma-phantomjs-launcher": "^1.0.4" }, "devDependencies": { - "karma-chrome-launcher": "^0.1.12", - "karma-firefox-launcher": "^0.1.6" + "karma-chrome-launcher": "^3.1.0", + "karma-firefox-launcher": "^1.3.0" } } diff --git a/test/clone-object.js b/test/clone-object.js index 86ec647..e62b7f6 100644 --- a/test/clone-object.js +++ b/test/clone-object.js @@ -3,6 +3,12 @@ describe('clone object', function () { var expected = {name: 'Ahmed', age: 27, skills: ['cycling', 'walking', 'eating']}, obj = {}; + var clone = function(o) { + return JSON.parse(JSON.stringify(o)) + }; + + obj = clone(expected); + expect(obj).toEqual(expected); expect(obj).not.toBe(expected); }); diff --git a/test/flatten-array.js b/test/flatten-array.js index c7f0632..ac4fe58 100644 --- a/test/flatten-array.js +++ b/test/flatten-array.js @@ -3,6 +3,21 @@ describe('flatten array', function () { var arr = [1, 2, [1, 2, [3, 4, 5, [1]]], 2, [2]], expected = [1, 1, 1, 2, 2, 2, 2, 3, 4, 5]; + var flatten = function(a) { + var res = []; + + for(var i = 0; i < a.length; i++) { + if(Array.isArray(a[i])) { + res = res.concat(flatten(a[i])) + } else { + res.push(a[i]); + } + } + return res.sort(); + }; + + arr = flatten(arr); + expect(arr).toEqual(expected); }); }); \ No newline at end of file diff --git a/test/scoping.js b/test/scoping.js index 557c54a..1403401 100644 --- a/test/scoping.js +++ b/test/scoping.js @@ -4,7 +4,7 @@ describe('scoping', function () { request; request = function (callback) { - return callback(); + return callback.bind(this)(); }; function Module () { @@ -16,7 +16,7 @@ describe('scoping', function () { }; Module.prototype.req = function() { - return request(this.method); + return request.bind(this)(this.method); }; expect(mod.req()).toBe('bar');