Skip to content

Commit

Permalink
Merge pull request #18 from OmkarKirpan/feature/update-test-cases
Browse files Browse the repository at this point in the history
update test case to only pick color buttons
  • Loading branch information
OmkarKirpan committed Oct 22, 2023
2 parents b7835dd + 7e790bd commit 2f9852e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
build:

name: node test
runs-on: ubuntu-latest

strategy:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Guess the Colors Game
# Guess the Colors Game [![Node.js CI](https://github.com/OmkarKirpan/GuessColors/actions/workflows/node.js.yml/badge.svg?branch=main)](https://github.com/OmkarKirpan/GuessColors/actions/workflows/node.js.yml)

This is a simple color guessing game built with React.js and Vite.js. The game is deployed on GitHub Pages and can be played [here](https://omkarkirpan.github.io/GuessColors/).

Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { render, fireEvent } from "@testing-library/react";
import '@testing-library/jest-dom'
import App, { generateRandomColor } from "../App";

const buttonColorRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;

// Helper function to convert RGB to Hex
function rgbToHex(rgb) {
// Choose correct separator
Expand Down Expand Up @@ -49,10 +51,10 @@ test("checks for correct answer", () => {
});

test("checks for wrong answer", () => {
const { getByTestId, getByText, queryByText, getAllByRole} = render(<App />);
const { getByTestId, getByText, queryByText, getAllByText} = render(<App />);
const guessMe = getByTestId("guess-me");
const color = guessMe.style.background;
const answers = getAllByRole('button')
const answers = getAllByText(buttonColorRegex)
const incorrectAnswer = Array.from(answers).find(
(ans) => ans.innerHTML.toUpperCase() !== rgbToHex(color).toUpperCase()
);
Expand Down

0 comments on commit 2f9852e

Please sign in to comment.