I saw an application built with Node.js and i don't understand how are the words describe
and it
available?
In the Browser Console it
is a function and describe
throws a RefferenceError
.
I know that they are used for testing.
const {assert} = require('chai');
const {jsdom} = require('jsdom');
const parseTextFromHTML = (htmlAsString, selector) => {
const selectedElement = jsdom(htmlAsString).querySelector(selector);
if (selectedElement !== null) {
return selectedElement.textContent;
} else {
throw new Error(`No element with selector ${selector} found in HTML string`);
}
};
describe('User visits index', () => {
describe('to post an order', () => {
it('starts with a blank order', () => {
browser.url('/');
assert.equal(browser.getText('#deliver-to span'), '');
assert.equal(browser.getText('#cake-type span'), '');
assert.equal(browser.getText('#fillings span'), '');
assert.equal(browser.getText('#size span'), '');
});
});
});
CodePudding user response:
mocha is a testing framework for NodeJS.
chai is an assertion library commonly used with Mocha.
The it() and describe() are from mocha, which you're implicitly importing by require ('chai')
:
Introduction to Testing in Mocha and Chai
Mocha Hooks:
- it: Defines a single test.
- describe: Defines a block of tests.