Skip to content

This is a simple project that allows a user to check if a word is a palindrome.

Notifications You must be signed in to change notification settings

MasterIfeanyi/react_palindrome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting started

Description

This is a simple project that allows a user to check if a word is a palindrome.

React

This project was bootstrapped with typescript and create-react-app. npx create-react-app .

Project Set-up

The dependencies required are all included in the package.json file. They will all be installed by running the npm install command.

To start the project run npm start.

Check out the web app

click the link below

Open Ifeanyi-palindrome-app to view it in the browser.

unit tests

toBeInTheDocument()

Every time I use expect("anything").toBeInTheDocument() on test file, when running the test I get:

TypeError: expect(...).toBeInTheDocument is not a function

solution

  1. install jest-dom npm i --save-dev @testing-library/jest-dom
  2. create a setupTests.js file in <rootDir>/src and put import '@testing-library/jest-dom'; in your file

source

stackoverflow question #1 - react-testing-library why is toBeInTheDocument() not a function

stackoverflow question #2 - Got TypeError: expect(...).toBeInTheDocument is not a function even after proper setup

prop drilling

When I tried to render the component Input.jsx while running the test I get:

expect(received).toBe(expected) // Object.is equality

    Expected: "racecar"
    Received: ""

solution

The component recieves props and I had to pass in those props as well while testing

const props = {
        setWord: jest.fn(),
        handleSubmit: jest.fn(),
        stop: "racecar",
    }

    render(<Input {...props} />);

source

stackoverflow question #1 - Test input Search box with React testing library

userEvent

I wanted to trigger user input, so I chose to use @testing-library/user-event

userEvent.type(inputEl, "racecar");


    await waitFor(() => {
        expect(inputEl.value).toBe("racecar");
    })

source

how to use userEvent

solving git error

This project was created from scratch and was not linked to the remote GitHub repository, so I started the process of setting a remote-tracking branch for my local repo. This is because I lost my .git sub-directory (somehow)

problem 1

action

git add . && git commit -m "switch branch, write unit test" && git push

error

fatal: The current branch main has no upstream branch.

solution

git push --set-upstream origin main

problem 2

action

git push --set-upstream origin main

error

fatal: failed to push some refs to github.com/**

solution

git pull --rebase origin main

problem 3

action

git pull

error

There is no tracking information for the current branch, If you wish to set tracking information for this branch you can do so with:

solution

git branch --set-upstream-to=origin/main main

problem 4

error

fatal: refusing to merge unrelated histories

solution

git pull origin main --allow-unrelated-histories

FINALLY

git pull --rebase origin main

git add .

git commit -m "resolve merge conflicts"

git push

Attention

When a merge conflict occurs , you can open individual file. You will get "<<<<<<< or >>>>>>>" symbols. These refer to your changes and the changes present on remote. You can manually edit the part that is requires. after that save the file and then do : git add

The merge conflicts will be resolved.

Resources

Dealing with non-fast-forward errors

How to fix ‘failed to push some refs to’ Git errors

Pulling is not possible because you have unmerged files

Git refusing to merge unrelated histories on rebase

Git push rejected "non-fast-forward"

What does "Git push non-fast-forward updates were rejected" mean?

"refusing to merge unrelated histories" failure while pulling to recovered repository

About

This is a simple project that allows a user to check if a word is a palindrome.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published