Skip to content

Commit

Permalink
Unit testing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornweb committed Apr 3, 2023
1 parent 316b901 commit 87cb90f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Unit Tests/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 8 additions & 0 deletions Unit Tests/validatepreviousURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var validatePreviousURL = function (url) {
//document.referrer
const urlBefore = url.indexOf('codepen') > -1;

return urlBefore
}

validatePreviousURL(document.referrer);
11 changes: 11 additions & 0 deletions Unit Tests/validatepreviousURL.test.js
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit 87cb90f

Please sign in to comment.