https://www.valentinog.com/blog/jest/ Flashcards
(22 cards)
What does testing mean?
Checking that our code meets some expectations.
What are the three main categories of testing?
Unit testing
Integration testing
UI testing
What is Jest?
A JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests.
What’s a good way to think about tests?
As bits of code that check if a given function produces the expected result.
What would a typical test flow look like?
import the function to test
give an input to the function
define what to expect as the output
check if the function produces the expected output
How would you create a new folder and initialize the project?
mkdir getting-started-with-jest && cd $_
npm init -y
How would you install jest via npm?
npm i jest –save-dev
How would you configure an NPM script for running our tests from the command line?
Open up package.json and configure the script named “test” for running Jest.
How would you open up package.json and configure the script named “test” for running Jest?
“scripts”: {
“test”: “jest”
},
What is a specification?
A written or verbal description of what to build.
What should we do for every object?
Check a property called “url”.
What happens when you check a property called “url” and the value of the property matches a given term?
Include the matching object in the resulting array.
What type of development should you follow?
test-driven development.
What does it mean to follow a test-driven development?
A discipline which imposes to write a failing test before starting to code.
Where does Jest expect to find the test files by default?
A folder called tests in your project folder.
How would you create a new folder called tests in your project folder?
cd getting-started-with-jest
mkdir __tests__
Then create a new file called filterByTerm.spec.js inside tests.
Why does this extension include “.spec.”?
filterByTerm.spec.js
It’s a convention borrowed from Ruby for marking the file as a specification for a given functionality.
Create a simple test block:
describe("Filter function", () => { // test stuff });
What is describe in this code?
describe("Filter function", () => { // test stuff });
A Jest method for containing one or more related tests.
What do you have to do every time you start writing a new suite of tests for a functionality?
Wrap it in a describe block.
How many arguments does describe take?
Two.
What arguments does describe take?
A string for describing the test suite and a callback function for wrapping the actual test.