Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

10 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Superhero battle react

Superheroes and villains are always battling it out, but how do we know who wins? In this test we will create a single page application to find out.

The superhero and villain characters along with their stats are stored in a public json file stored in AWS S3 - https://s3.eu-west-2.amazonaws.com/build-circle/characters.json

During a battle the character with the highest score wins.

We expect the solution to be simple, readable, and to be supported by good unit tests (reliable, fast, and asserting behaviour).

Getting started

The app uses Node 24 (see .nvmrc), Vite and Vitest.

yarn install
yarn start

yarn start (or yarn dev) runs the app at http://localhost:5173. yarn build creates a production build in dist/.

1. Run the tests

yarn test

This runs the tests once. Use yarn test:watch to re-run them as you change code.

Tests use Vitest with React Testing Library. The API matches Jest (test, expect and the jest-dom matchers are available globally); use vi.fn() and vi.mock() where you would use jest.fn() and jest.mock().

2. Check the code

Familiarise yourself with the code. What does it all do? What do the tests do?

3. Hero and villain name input

We need a way of taking in a hero name and a villain name as inputs, and a battle button to trigger the fight!

4. Triggering the battle

When the battle button is clicked, we need to load the characters JSON file and find the characters by their name. We can then compare the scores of each character, the winner has the higher score. We should show the winner on the page after the battle is over.

5. Weaknesses

Each hero usually has a nemesis. This is captured in the weakness field in the JSON. If a hero is fighting a villain that matches the villain in their weakness field their score is weakened by 1 point. Lets write some code to handle this.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

10 watching

Forks

Releases

Packages

Used by

Contributors

Languages