|
518 | 518 | }
|
519 | 519 | }
|
520 | 520 | p creates a new function each render-cycle
|
| 521 | + |
| 522 | + //TODO: discuss correct event binding with david |
521 | 523 |
|
522 | 524 | section.emphatic-text(data-bespoke-backdrop='emphatic')
|
523 | 525 | h2 Container & Presentational Components
|
@@ -599,12 +601,59 @@ html
|
599 | 601 | section
|
600 | 602 | h3 Jest
|
601 | 603 | ul
|
| 604 | + li Framework developed by Facebook |
602 | 605 | li JavaScript testing in general
|
| 606 | + li IntelliJ integration since 2017.1 |
603 | 607 |
|
604 | 608 | section
|
605 | 609 | h3 Enzyme
|
606 | 610 | 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(<ActionButtons 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 <div><button onClick={props.onButtonClick}>ClickMe</button></div>; |
| 649 | + } |
| 650 | + |
| 651 | + const mockOnClick = jest.fn(); |
| 652 | + const wrapper = mount(<MyComponent onButtonClick={mockOnClick} />); |
| 653 | + wrapper.find(‘button’).simulate(‘click’); |
| 654 | + expect(mockOnClick).toHaveBeenCalled(); |
| 655 | + |
| 656 | + //TODO: adjust unittest-examples for fancyworkshopapp |
608 | 657 |
|
609 | 658 | section.emphatic-text(data-bespoke-backdrop='emphatic')
|
610 | 659 | h2 State Management
|
|
0 commit comments