Skip to content

Commit

Permalink
add counter and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samilieberman committed Nov 25, 2022
1 parent 2005307 commit a39968c
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 82 deletions.
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "react-scripts test --watchAll=false --coverage",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand All @@ -34,5 +34,18 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"jest": {
"collectCoverageFrom": [
"src/components/**/*.{js,jsx,ts,tsx}"
],
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
}
}
27 changes: 0 additions & 27 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
Expand All @@ -23,16 +9,3 @@
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
25 changes: 0 additions & 25 deletions src/App.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Counter from './Counter';
import '../App.css';

function App() {
return (
<div className="App">
<h1>Welcome to my website!</h1>
<Counter />
</div>
);
}

export default App;
19 changes: 19 additions & 0 deletions src/components/Counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { useState } from "react";

export default function Counter() {
const [count, setCount] = useState(0);
function increment() {
setCount((count) => count + 1);
}
function decrement() {
setCount((count) => count - 1);
}
return (
<div>
<h2>Counter</h2>
<p data-testid="count">{count}</p>
<button onClick={increment}> + </button>
<button onClick={decrement}> - </button>
</div>
);
}
8 changes: 1 addition & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import App from './components/App';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
1 change: 0 additions & 1 deletion src/logo.svg

This file was deleted.

13 changes: 0 additions & 13 deletions src/reportWebVitals.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/tests/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from '../components/App';

test('renders welcome message', () => {
render(<App />);
const welcomeMessage = screen.getByText(/Welcome to my website!/i);
expect(welcomeMessage).toBeInTheDocument();
});
22 changes: 22 additions & 0 deletions src/tests/Counter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// import necessary react testing library helpers here
// import the Counter component here

beforeEach(() => {
// Render the Counter component here
})

test('renders counter message', () => {
// Complete the unit test below based on the objective in the line above
});

test('should render initial count with value of 0', () => {
// Complete the unit test below based on the objective in the line above
});

test('clicking + increments the count', () => {
// Complete the unit test below based on the objective in the line above
});

test('clicking - decrements the count', () => {
// Complete the unit test below based on the objective in the line above
});

0 comments on commit a39968c

Please sign in to comment.