Skip to content

Instantly share code, notes, and snippets.

View rabeehebrahim's full-sized avatar

Rabeeh Ebrahim rabeehebrahim

View GitHub Profile
@rabeehebrahim
rabeehebrahim / users.test.ts
Created June 6, 2023 17:00
Replacing jwt token verification middleware when testing end points in jest.
// before importing app and supertest
// you should write jest.mock function
// with the first argument is the path of your
// actual middleware and second argument write a
// fake middle function.
jest.mock('../middleware/verifyToken', () => {
return jest.fn((req, res, next) => {
next()
})
@rabeehebrahim
rabeehebrahim / app.js
Last active October 28, 2022 06:10
React Input Field Validation: if the value is empty in the form and user click submit, then show 'Name must not be empty' else show nothing.
import react, {useRef, useState} from "react";
const SimpleInput = (props) => {
const [enteredName, setEnteredName] = useState('')
const [enteredNameIsValid, setEnteredNameIsValid] = useState(true)
const nameInputChangeHandler = event => {
setEnteredName(event.target.value)
}