-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing React with Jest #7
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47d4f45
add test for the operate and calculator
nedjwab f9351b9
Add The navbar test
nedjwab 0cc473e
Fix linter errors
nedjwab e4ce81a
Add test for "." , "+/-" and "=" buttons
nedjwab e96611c
Add lisence to the README file
nedjwab a201558
Add heroku link
nedjwab 2e6298c
Update README
nedjwab File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders correctly 1`] = ` | ||
<footer> | ||
Made By @nedjwa_Bouraiou | ||
</footer> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders correctly 1`] = ` | ||
<div | ||
className="home-container" | ||
> | ||
<img | ||
alt="gif" | ||
className="brain-img" | ||
src="https://upload.wikimedia.org/wikipedia/commons/e/e2/Math_-_Idil_Keysan_-_Wikimedia_Giphy_stickers_2019.gif" | ||
/> | ||
<div | ||
className="body" | ||
> | ||
<h2> | ||
Welcome to our page! | ||
</h2> | ||
<div | ||
className="contenu" | ||
> | ||
While it may seem like math problems like the above have no real use in life, this couldn’t be farther from the truth! Math is incredibly important in our lives and, without realizing it, we use mathematical concepts, as well as the skills we learn from doing math problems, every day. The laws of mathematics govern everything around us, and without a good understanding of them, one can encounter significant problems in life. | ||
</div> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders correctly 1`] = ` | ||
<header> | ||
<h1 | ||
id="logo" | ||
> | ||
Math Magicians | ||
</h1> | ||
<nav | ||
className="nav-items" | ||
> | ||
<a | ||
className="nav-item" | ||
href="/" | ||
onClick={[Function]} | ||
> | ||
Home | ||
</a> | ||
<a | ||
className="nav-item" | ||
href="/calculator" | ||
onClick={[Function]} | ||
> | ||
Calculator | ||
</a> | ||
<a | ||
className="nav-item" | ||
href="/quote" | ||
onClick={[Function]} | ||
> | ||
Quotes | ||
</a> | ||
</nav> | ||
</header> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders correctly 1`] = ` | ||
<div | ||
className="quotes" | ||
> | ||
<ul> | ||
<li> | ||
Without mathematics, there’s nothing you can do. Everything around you is mathematics. Everything around you is numbers. | ||
|
||
<span> | ||
— Shakuntala Devi, Indian writer and mental calculator | ||
</span> | ||
</li> | ||
<br /> | ||
<li> | ||
Mathematics as an expression of the human mind reflects the active will, the contemplative reason, and the desire for aesthetic perfection. Its basic elements are logic and intuition, analysis and construction, generality and individuality. | ||
|
||
<span> | ||
— Richard Courant, German-American mathematician | ||
</span> | ||
</li> | ||
<br /> | ||
<li> | ||
What is mathematics? It is only a systematic effort of solving puzzles posed by nature. | ||
|
||
<span> | ||
— Shakuntala Devi | ||
</span> | ||
</li> | ||
</ul> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import calculate from '../logic/calculate'; | ||
|
||
describe('Test for calculate function', () => { | ||
test('Test AC button', () => { | ||
const obj = { | ||
next: null, | ||
total: 5, | ||
operation: '+', | ||
}; | ||
|
||
const result = calculate(obj, 'AC'); | ||
|
||
expect(result).toStrictEqual({ | ||
total: null, | ||
next: null, | ||
operation: null, | ||
}); | ||
}); | ||
|
||
test('Test Equal button', () => { | ||
const obj = { | ||
next: 3, | ||
total: 5, | ||
operation: '+', | ||
}; | ||
|
||
const result = calculate(obj, '='); | ||
|
||
expect(result).toStrictEqual({ | ||
total: '8', | ||
next: null, | ||
operation: null, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import Footer from '../components/footer'; | ||
|
||
it('renders correctly', () => { | ||
const footer = renderer | ||
.create(<Footer />) | ||
.toJSON(); | ||
expect(footer).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import Home from '../components/home'; | ||
|
||
it('renders correctly', () => { | ||
const home = renderer | ||
.create(<Home />) | ||
.toJSON(); | ||
expect(home).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import Navbar from '../components/navBar'; | ||
|
||
it('renders correctly', () => { | ||
const navbar = renderer | ||
.create(<Router><Navbar /></Router>) | ||
.toJSON(); | ||
expect(navbar).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import operate from '../logic/operate'; | ||
|
||
describe('Test for calculate function', () => { | ||
test('Test multiple function button', () => { | ||
// arrange | ||
const numOne = 2; | ||
const numTwo = 3; | ||
const operation = 'x'; | ||
|
||
const result = operate(numOne, numTwo, operation); | ||
|
||
expect(Number(result)).toBe(6); | ||
}); | ||
|
||
test('Test sum function button', () => { | ||
const numOne = 2; | ||
const numTwo = 3; | ||
const operation = '+'; | ||
|
||
const result = operate(numOne, numTwo, operation); | ||
|
||
expect(Number(result)).toBe(5); | ||
}); | ||
|
||
test('Test div function button', () => { | ||
const numOne = 8; | ||
const numTwo = 4; | ||
const operation = '÷'; | ||
|
||
const result = operate(numOne, numTwo, operation); | ||
|
||
expect(Number(result)).toBe(2); | ||
}); | ||
|
||
test('Test mod function button', () => { | ||
const numOne = 8; | ||
const numTwo = 4; | ||
const operation = '%'; | ||
|
||
const result = operate(numOne, numTwo, operation); | ||
|
||
expect(Number(result)).toBe(0); | ||
}); | ||
test('Test minis function button', () => { | ||
const numOne = 8; | ||
const numTwo = 4; | ||
const operation = '-'; | ||
|
||
const result = operate(numOne, numTwo, operation); | ||
|
||
expect(Number(result)).toBe(4); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import Quote from '../components/quote'; | ||
|
||
it('renders correctly', () => { | ||
const quote = renderer | ||
.create(<Quote />) | ||
.toJSON(); | ||
expect(quote).toMatchSnapshot(); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.