Skip to content

Commit

Permalink
tests using supertest
Browse files Browse the repository at this point in the history
  • Loading branch information
Shay2Shay committed May 1, 2024
1 parent 7959c48 commit 5b7a8be
Show file tree
Hide file tree
Showing 8 changed files with 631 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/node_modules
/node_modules
mongoURL.js
.env
22 changes: 9 additions & 13 deletions demo.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
const { default: expect } = require("expect")
const fs = require('fs')
const { string } = require("yargs")

async function getAllData(){
let data = await fetch('http://localhost:8080/api/customer/viewServices')
data = await data.json()
fs.writeFileSync('log.txt', JSON.stringify(data))
return data
}
require('dotenv').config()
const { expect } = require("expect")
const supertest = require('supertest')
const {app} = require('./server/test_server.js')

test('demo testing for sum', () => {
expect(1+2).toBe(3)
expect(1 + 2).toBe(3)
})

test('testing login', async () => {
expect( await getAllData() ).not.toBe(null)
test('testing get all services', async () => {
const response = await supertest(app).get("/api/customer/viewServices")
expect(response).not.toBe(null)
return
})
35 changes: 35 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// jest.config.js
module.exports = {
roots: ["./"],
collectCoverageFrom: ["./**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts"],
// setupFilesAfterEnv: ["<rootDir>/setupTests.js"],
testMatch: [
"./**/__tests__/**/*.{js,jsx,ts,tsx}",
"./**/*.{spec,test}.{js,jsx,ts,tsx}",
],
testEnvironment: "node",
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "./node_modules/babel-jest",
},
transformIgnorePatterns: ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$"],
modulePaths: [],
moduleNameMapper: {
"^react-native$": "react-native-web",
"\\.(css|less|scss|sss|styl)$": "./node_modules/jest-css-modules",
},
moduleFileExtensions: [
"web.js",
"js",
"json",
"web.jsx",
"jsx",
"node",
"ts",
"tsx",
],
// watchPlugins: [
// "jest-watch-typeahead/filename",
// "jest-watch-typeahead/testname",
// ],
};

Loading

0 comments on commit 5b7a8be

Please sign in to comment.