Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. const Mocha = require('mocha');
  2. const assert = require('assert');
  3. const mocha = new Mocha();
  4. const jsdom = require("jsdom");
  5.  
  6. const { JSDOM } = jsdom;
  7. const { document } = (new JSDOM('<!DOCTYPE html><div class="class1">Hello World</div>')).window;
  8.  
  9. function getContentByClassName(className) {
  10. let elements = document.getElementsByClassName(className);
  11.  
  12. if (elements.length === 0) {
  13. return '';
  14. }
  15.  
  16. return elements[0].textContent;
  17. }
  18.  
  19. mocha.suite.emit('pre-require', this, 'solution', mocha);
  20.  
  21. describe('Test suite', function() {
  22. it('should work', function() {
  23. assert(true);
  24. });
  25. });
  26.  
  27. describe('#getContentByClassName', function() {
  28. it('should return the content of a class', function() {
  29. assert(getContentByClassName('class1') === 'Hello World');
  30. });
  31.  
  32. it('should return an empty string if given a non existent class', function() {
  33. assert(getContentByClassName('class2') === '');
  34. });
  35. });
  36.  
  37. mocha.run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement