This is a simple application that calls a graphql endpoint for a country data And has a simple form to encrypt the returned data with a Caesar Cipher
Clone down the project and install the dependencies:
npm install
Run the development server:
npm run dev
# or
yarn dev
Open http://localhost:3000 with your browser to see the result.
- Your unit tests are the documentation for your code
- Structure of A Unit Test
- Given, When, Then
- Arrange, Act, Assert
- They should be independent and testing should be targeted to smallest unit of your code
- If something is hard to test then that could be a code smell
- Can the code be refactored to adhere to the Single Responsibility Principle?
- Are the abstractions correct?
- One assertion per unit test
- Set Up a Clean Environment For Each Test (beforeEach, afterEach, beforeAll, afterAll)
- Use Mocks to test effectively
Testings pure functions can be a great way to get started unit testing and get familiar with the testing framework you are using. For this example, we will test a function that implements the Caesar Cipher
react-testing-library makes it easier to test how the user will interact with our app. As we dive deeper we will take a look at how we can mock external graphql calls and test how our app is being used based on those dependencies