Skip to content

Instantly share code, notes, and snippets.

@RebeccaBakels
Created March 5, 2021 14:29
Show Gist options
  • Save RebeccaBakels/fa3d200cef946d753397df9fa4c83413 to your computer and use it in GitHub Desktop.
Save RebeccaBakels/fa3d200cef946d753397df9fa4c83413 to your computer and use it in GitHub Desktop.
After entering into your project in the console
yarn test 'name' ex App
look at App.test.js
expect(name of function).toBeInTheDocument(answer);
import { render, screen } from '@testing-library/react';
import App from './App';
import {calcTax, isOfAge} from './helpers'
test('check tax calc 1', () => {
expect(calcTax(.10, 50.00)).toBe(5.0)
})
test('check if 18 fails drinking age', () => {
expect(isOfAge(18)).toBe(false)
})
test('check if 45 fails drinking age', () => {
expect(isOfAge(45)).toBe(true)
})
test('check if 21 fails drinking age', () => {
expect(isOfAge(21)).toBe(true)
})
test('check if -99 fails drinking age', () => {
expect(isOfAge(-99)).toBe(false)
})
test('check if xyz fails drinking age', () => {
expect(isOfAge('xyz')).toBe(false)
})
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
test('renders learn react about the nav', () => {
render(<App />);
const linkElement = screen.getByText(/about/i);
expect(linkElement).toBeInTheDocument();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment