Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import React from 'react';
  2. import Info from './info';
  3. import { assert } from 'chai';
  4. import { shallow } from 'enzyme';
  5.  
  6. const infoMessage = 'Something important here';
  7. function renderInfoComponent(visible) {
  8. return shallow(
  9. <Info visible={visible}>
  10. {infoMessage}
  11. </Info>
  12. );
  13. }
  14.  
  15. function assertInfoVisible(wrapper) {
  16. assert.isOk(wrapper);
  17. const html = wrapper.html()
  18. assert.include(html, 'Show info');
  19. assert.notInclude(html, infoMessage);
  20. }
  21.  
  22. function assertInfoHidden(wrapper) {
  23. assert.isOk(wrapper);
  24. const html = wrapper.html()
  25. assert.include(html, 'Hide info');
  26. assert.include(html, infoMessage);
  27. }
  28.  
  29. describe('Info', function () {
  30. it('Renders "show info"', function () {
  31. const wrapper = renderInfoComponent(false);
  32. assertInfoVisible(wrapper);
  33. });
  34.  
  35. it('Renders info and "Hide info" button', function () {
  36. const wrapper = renderInfoComponent(true);
  37. assertInfoHidden(wrapper);
  38. });
  39.  
  40. it('Can toggle info', function () {
  41. const wrapper = renderInfoComponent(false);
  42. assertInfoVisible(wrapper);
  43.  
  44. wrapper.find('#toggleInfo').simulate('click');
  45. assertInfoHidden(wrapper);
  46.  
  47. wrapper.find('#toggleInfo').simulate('click');
  48. assertInfoVisible(wrapper);
  49. });
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement