https://www.valentinog.com/blog/jest/ Flashcards

1
Q

What does testing mean?

A

Checking that our code meets some expectations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three main categories of testing?

A

Unit testing
Integration testing
UI testing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Jest?

A

A JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s a good way to think about tests?

A

As bits of code that check if a given function produces the expected result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What would a typical test flow look like?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you create a new folder and initialize the project?

A

mkdir getting-started-with-jest && cd $_

npm init -y

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you install jest via npm?

A

npm i jest –save-dev

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would you configure an NPM script for running our tests from the command line?

A

Open up package.json and configure the script named “test” for running Jest.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you open up package.json and configure the script named “test” for running Jest?

A

“scripts”: {
“test”: “jest”
},

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a specification?

A

A written or verbal description of what to build.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What should we do for every object?

A

Check a property called “url”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What happens when you check a property called “url” and the value of the property matches a given term?

A

Include the matching object in the resulting array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What type of development should you follow?

A

test-driven development.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does it mean to follow a test-driven development?

A

A discipline which imposes to write a failing test before starting to code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Where does Jest expect to find the test files by default?

A

A folder called tests in your project folder.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How would you create a new folder called tests in your project folder?

A

cd getting-started-with-jest
mkdir __tests__

Then create a new file called filterByTerm.spec.js inside tests.

17
Q

Why does this extension include “.spec.”?

filterByTerm.spec.js

A

It’s a convention borrowed from Ruby for marking the file as a specification for a given functionality.

18
Q

Create a simple test block:

A
describe("Filter function", () => {
  // test stuff
});
19
Q

What is describe in this code?

describe("Filter function", () => {
  // test stuff
});
A

A Jest method for containing one or more related tests.

20
Q

What do you have to do every time you start writing a new suite of tests for a functionality?

A

Wrap it in a describe block.

21
Q

How many arguments does describe take?

A

Two.

22
Q

What arguments does describe take?

A

A string for describing the test suite and a callback function for wrapping the actual test.