From 9001607a10e55faeb47e9a9af87bb1f1a87dc566 Mon Sep 17 00:00:00 2001 From: RebeccaHough Date: Mon, 20 Jul 2020 15:36:29 +0100 Subject: [PATCH] add solution --- .gitignore | 2 ++ .travis.yml | 2 ++ karma.conf.js | 2 +- package.json | 9 ++++----- test/clone-object.js | 2 ++ test/flatten-array.js | 6 ++++++ test/scoping.js | 2 +- 7 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index da23d0d..926b21b 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 diff --git a/.travis.yml b/.travis.yml index 7caf3cd..f0b61f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: node_js node_js: - "node" - "iojs" +addons: + chrome: stable before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start diff --git a/karma.conf.js b/karma.conf.js index b80efa5..a68cf0d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -2,7 +2,7 @@ // Generated on Wed Jun 18 2014 09:33:44 GMT+0100 (BST) module.exports = function(config) { - var browsers = ['PhantomJS', 'Firefox']; + var browsers = ['Firefox', 'ChromeHeadless']; if (!process.TRAVIS) { browsers.push('Chrome'); diff --git a/package.json b/package.json index 7d46b91..0533321 100644 --- a/package.json +++ b/package.json @@ -26,12 +26,11 @@ }, "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" }, "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..dd5ea34 100644 --- a/test/clone-object.js +++ b/test/clone-object.js @@ -3,6 +3,8 @@ describe('clone object', function () { var expected = {name: 'Ahmed', age: 27, skills: ['cycling', 'walking', 'eating']}, obj = {}; + obj = {...expected, skills: [...expected.skills]} + expect(obj).toEqual(expected); expect(obj).not.toBe(expected); }); diff --git a/test/flatten-array.js b/test/flatten-array.js index c7f0632..0957e8c 100644 --- a/test/flatten-array.js +++ b/test/flatten-array.js @@ -3,6 +3,12 @@ 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]; + function flatten (arr) { + return arr.reduce((acc, curr) => Array.isArray(curr) ? acc.concat(flatten(curr)): acc.concat(curr), []) + } + + arr = flatten(arr).sort() + expect(arr).toEqual(expected); }); }); \ No newline at end of file diff --git a/test/scoping.js b/test/scoping.js index 557c54a..5100a0a 100644 --- a/test/scoping.js +++ b/test/scoping.js @@ -16,7 +16,7 @@ describe('scoping', function () { }; Module.prototype.req = function() { - return request(this.method); + return request(() => this.method()); }; expect(mod.req()).toBe('bar');