Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit ec63aa9

Browse files
author
Dominik Sumer
committed
added slides for unit tests
1 parent 4379f97 commit ec63aa9

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/images/folder_structure.png

5.69 KB
Loading

src/index.jade

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ html
518518
}
519519
}
520520
p creates a new function each render-cycle
521+
522+
//TODO: discuss correct event binding with david
521523
522524
section.emphatic-text(data-bespoke-backdrop='emphatic')
523525
h2 Container & Presentational Components
@@ -599,12 +601,59 @@ html
599601
section
600602
h3 Jest
601603
ul
604+
li Framework developed by Facebook
602605
li JavaScript testing in general
606+
li IntelliJ integration since 2017.1
603607

604608
section
605609
h3 Enzyme
606610
ul
607-
li Test your React Components
611+
li Testing utilities for React
612+
li Developed by AirBnB
613+
li Different rendering modes for React components
614+
li Simulate Events in your components
615+
616+
section
617+
h3 Folder structure
618+
img(src="./images/folder_structure.png", style="width: 60%;margin:20px")
619+
620+
section
621+
h3 Write your first test
622+
pre
623+
code.language-javascript.
624+
import React from 'react';
625+
import {shallow} from 'enzyme';
626+
import ActionButtons from './ActionButtons';
627+
628+
describe('ActionButtons', () => {
629+
it('should render submit button correctly', () => {
630+
const okText = 'OK';
631+
const component = shallow(&ltActionButtons textOk={okText} />);
632+
expect(component.find('button[type="submit"]').text()).toBe(okText);
633+
});
634+
});
635+
636+
section
637+
h3 Enzyme Render Modes
638+
ul
639+
li shallow
640+
li mount
641+
li render
642+
643+
section
644+
h3 Simulate Events
645+
pre
646+
code.language-javascript.
647+
function MyComponent(props) {
648+
return &ltdiv>&ltbutton onClick={props.onButtonClick}>ClickMe&lt/button>&lt/div>;
649+
}
650+
651+
const mockOnClick = jest.fn();
652+
const wrapper = mount(&ltMyComponent onButtonClick={mockOnClick} />);
653+
wrapper.find(‘button’).simulate(‘click’);
654+
expect(mockOnClick).toHaveBeenCalled();
655+
656+
//TODO: adjust unittest-examples for fancyworkshopapp
608657
609658
section.emphatic-text(data-bespoke-backdrop='emphatic')
610659
h2 State Management

0 commit comments

Comments
 (0)