From 87cb90f080d461e18a910662c5cdfe71956255a5 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 3 Apr 2023 20:01:48 +1200 Subject: [PATCH] Unit testing examples --- Unit Tests/package.json | 20 ++++++++++++++++++++ Unit Tests/validatepreviousURL.js | 8 ++++++++ Unit Tests/validatepreviousURL.test.js | 11 +++++++++++ 3 files changed, 39 insertions(+) create mode 100644 Unit Tests/package.json create mode 100644 Unit Tests/validatepreviousURL.js create mode 100644 Unit Tests/validatepreviousURL.test.js diff --git a/Unit Tests/package.json b/Unit Tests/package.json new file mode 100644 index 0000000..9f8606d --- /dev/null +++ b/Unit Tests/package.json @@ -0,0 +1,20 @@ +{ + "name": "tests", + "version": "1.0.0", + "description": "", + "main": "server.js", + "dependencies": { + "cors": "^2.8.5", + "express": "^4.17.1" + }, + "devDependencies": { + "jest": "^26.6.3" + }, + "scripts": { + "test": "npx jest", + "start": "node server.js" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/Unit Tests/validatepreviousURL.js b/Unit Tests/validatepreviousURL.js new file mode 100644 index 0000000..3ba4054 --- /dev/null +++ b/Unit Tests/validatepreviousURL.js @@ -0,0 +1,8 @@ +var validatePreviousURL = function (url) { +//document.referrer +const urlBefore = url.indexOf('codepen') > -1; + +return urlBefore +} + +validatePreviousURL(document.referrer); \ No newline at end of file diff --git a/Unit Tests/validatepreviousURL.test.js b/Unit Tests/validatepreviousURL.test.js new file mode 100644 index 0000000..b80cd56 --- /dev/null +++ b/Unit Tests/validatepreviousURL.test.js @@ -0,0 +1,11 @@ +var validatepreviousURL = function (url) { + //document.referrer + const urlBefore = url.indexOf('codepen') > -1; + + return urlBefore +} + +//Tests +test('Retuns False cause previous URL does not match with the regex', () => { +expect(validatepreviousURL("google.com")).toBe(false) +}) \ No newline at end of file