Testing Flashcards

1
Q

What does ‘create-react-app’ {filename} do?

A

It creates a react application with packages/dependencies that you need

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

After you set up your react application what is the ‘App.js’ file?

A

It is the Root component

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

How are you given testing functionality in create-react-app?

A

It comes with a testing functionality right out of the box, ready to go. It utilizes npm run test in the root directory and utilizes ‘App.test.js’

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

What dependencies did we get with create-react-app?

A

1) React . - The React Library
2) Webpack - Links together JS files
3) Babel - Turns ES6 and JSX into ES5 code
4) Jest - Automated test runner

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

What happens when we execute the NPM test command at the terminal?

A

1) We run ‘npm run test’ at the terminal
2) Jest test runner starts up
3) Jest finds all files ending in .test.js and executes tests inside of them
4) Jest prints out results of tests to the terminal
5) Jest waits for a file to change, then runs all tests again

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

What is the framework to follow to understand what tests you should write in your application?

A

Follow these three steps:

1) Look at each individual part of your application. Every reducer, every action creator, every component
2) Imagine telling a friend ‘heres what this piece of code does’
3) Write a test to verify each part does what you expect

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

In our ‘comments’ app, if we wanted to know all the tests in the app, what would they be?

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

What is the main construct of our testing suite?

A

it ( description of the test, function containing our test logic)

1) it is a global function - no need to import. It is used to organize all the different test that we write inside of a single file. So for each test we write we will call the IT function exactly one time
2) The first argument to the IT function is a string that is a description of the test that you are going to write. String description solely for ourselves
3) The second argument is the body, test logic that wants to execute. Runs what the 1st argument states

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

How can we trick React with JSDOM?

A

1) When we run JEST it’s being ran in our command line environment. From the terminal. Issue is that if we run React, it thinks it should be ran inside the browser. ONLY inside the browser does it work
2) So, Dependency is called JSDOM, code implementation of how the browser works. It fakes out the existence of a browser.
3) So then, React takes the App Component and creates the HTML produces by the App and sticks it in JSDOM’s div element

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

What is ‘expect’ when you test?

A

expect(value that we are inspecting).matcher statement(value that we expect to see);

1) Expect - Global function, the object property array etc. the thing we are looking at. Example, we want to inspect the HTML contained by that div element
2) Value that we are inspecting - The thing we want to verify
3) Matcher Statement - Designates how we want to inspect the ‘subject’.
4) Expected value 0 its what we want our ‘subject’ to be

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

What’s a general rule about working with tests and internal workings of a component?

A

If we write a test for a component, then that test shouldn’t mess with the inner workings or the actual implementation details of any other component if possible

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

What is enzyme? npm install –save enzyme-adapter-react-16

A

Open source package created by Airbnb specifically made for testing re-act components a little bit easier

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

After you’ve dependency installed enzyme, what file do you need to create?

A

In SRC, you should create setupTests.js

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

So how does Enzyme really function?

A

Gives us three additional capabilities for writing our tests. Each of these render functions are going to take instance of components, take them or attempt to render them in a slightly different fashion and will return

1) Static Renderer - Render the given component and return plain HTML. A function that allows only HTML. Doesn’t allow us to do clicking etc.
2) Shallow Renderer- Render just the given component and none of its children. Really analyzing
3) Full DOM Renderer- Render the component and all of its children and let us modify it afterwards. Sends an object back that we can use to interact with the component. Like click events etc

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

Explain the ‘beforeEach’ helper function in jest

A

Extract out or pull out logic for each file. Before each test, we are going to do some setup of logic

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

Which package for the FullDOM rendered in enzyme?

A

You need to import mount from enzyme? Remember to do beforeEach and afterEach for each it function

17
Q

How do you simulate an event for testing?

A

1) Find the textarea element
2) Simulate a ‘change’ event
3) Provide a fake event object
4) Force the component to update
5) Assert that the textareas value has changed

18
Q

Using enzyme, what is the function that can simulate a change event?

A

simulate method. You can ‘simulate’ a given event

19
Q

How do you pass a mock object for testing in enzyme?

A

You utilize the mock object: A mock event object that will be merged with the event object passed to the handlers

You want to trick the event handler with this kind of custom or fake or mock event object

20
Q

Does react re-render the component instantly after ‘setstate’?

A

No, it queues and react gets to it whenever it can. In our test, we are going to need to use enzyme’s .update to force update the component

21
Q

What is the ‘describe’ function in jest?

A

Is used to group together certain sets of test that have some common set up or tear down for each of them

22
Q

Describe the mechanics of how provider component works from react-redux?

A

It works with all the connects in the App to gain access to the redux store

23
Q

What is a cherriowrapper?

A

It’s something similar to jQuery, it allows us to kind of crawl or run queries or essentially selectors over snippets of each HTML

24
Q

What is redux promise?

A

Use it to handle asynchronous action creators or action creators that try to make network requests

25
Q

What are unit tests?

A

Wheer we isolate a very small piece of functionality within our code base and test it in isolation

26
Q

What are integration tests?

A

Where we try to simultaneously test many parts of our application

‘Does clicking ‘Fetch Comments’ show a list of ‘LI’’s on the screen

27
Q

Why would a fetch to an outside API (such as the comments API) fail?

A

Because you are in your JSDOM API ‘fake’ browser environment in the CLE that contains Jest. Within Jest, Axios

28
Q

What is moxios?

A

It’s ‘mock out the axios api’. It watches axios for the request and any time it does we’re going to trick axios into thinking that it instantly gets a response.

You would never use moxios in a production evironment because it’s sole purpose is to fake out requests or to trick axios ino thinking a request was succcessfully issued

29
Q
A
30
Q

App Wrapup the test suite

A

1) Units tests vs integration tests… a ton of unit tests, it’s fine, but integration tests are much better