Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Mocha = require('mocha');
- const assert = require('assert');
- const mocha = new Mocha();
- const jsdom = require("jsdom");
- const { JSDOM } = jsdom;
- const { document } = (new JSDOM('<!DOCTYPE html><div class="class1">Hello World</div>')).window;
- function getContentByClassName(className) {
- let elements = document.getElementsByClassName(className);
- if (elements.length === 0) {
- return '';
- }
- return elements[0].textContent;
- }
- mocha.suite.emit('pre-require', this, 'solution', mocha);
- describe('Test suite', function() {
- it('should work', function() {
- assert(true);
- });
- });
- describe('#getContentByClassName', function() {
- it('should return the content of a class', function() {
- assert(getContentByClassName('class1') === 'Hello World');
- });
- it('should return an empty string if given a non existent class', function() {
- assert(getContentByClassName('class2') === '');
- });
- });
- mocha.run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement