Sphinx is a delightful JavaScript Testing Library with a focus on simplicity.
For now we provide the library only directly via GitHub install.
npm install github:getmimo/sphinx
"dependencies": {
"sphinx": "github:getmimo/sphinx"
},
Simply require the builder function and build your own personal Sphinx
let fs = require('fs');
let htmlCode = fs.readFileSync('src/examples/index.html', 'utf8');
let HTMLParser = require('node-html-parser');
let root = HTMLParser.parse(htmlCode);
let sphinx = require('sphinx').buildSphinx(root, htmlCode, test, expect);
after you have successfully built it you can use it like this
sphinx.test('Make sure to start your code with: <!doctype html>.', () => {
openingTagIndex = htmlCode.indexOf('<!doctype html>');
expect(openingTagIndex).toEqual(0);
});
sphinx.elementExists({ elementName: 'html' });
sphinx.elementExists({ elementName: 'body' });
sphinx.elementExists({ elementName: 'script' });
sphinx.elementExists({ elementName: 'h1' });
sphinx.elementExists({ elementName: 'p' });
let firstPClosingTagIndex = sphinx.getEndOfClosingTagIndexForElement({
elementName: 'p',
});
sphinx.elementExists({ elementName: 'p', searchIndex: firstPClosingTagIndex });
sphinx.emptyElementExists({ elementName: 'img' });
sphinx.firstElementIsInsideSecond({
firstElementName: 'body',
secondElementName: 'html',
});
sphinx.firstElementIsInsideSecond({
firstElementName: 'script',
secondElementName: 'body',
});
Thomas Sattlecker (@ThomasS09) - Mimo
Christopher Simerle (@simerle_c) - Mimo