Files
docsify/tests/unit/example.test.js
T
John Hildenbiddle aed09be687 Isolate e2e, integration, and unit test environments
- Setup projects for e2e, integration, and unit tests in Jest configuration
- Setup /tests/e2e/ tests for Jest+PlayWright
- Setup /tests/integration/ tests for Jest
- Setup /tests/unit/ tests for Jest
- Setup eslint for Jest and Jest+Playwright environments
- Move e2e configuration files into separate folder
- Update e2e example tests
- Update unit example tests
- Update HTML fixtures
2020-07-13 18:26:45 -04:00

35 lines
1.1 KiB
JavaScript

// Suite
// -----------------------------------------------------------------------------
describe(`Example Tests`, function() {
// Tests
// ---------------------------------------------------------------------------
test('javascript (node)', async () => {
function add(...addends) {
return addends.reduce(
(accumulator, currentValue) => accumulator + currentValue
);
}
const testValue = add(1, 2, 3);
expect(testValue).toBe(6);
});
test('dom manipulation (jsdom)', async () => {
const testText = 'This is a test';
const testHTML = `<h1>Test</h1><p>${testText}</p>`;
// Inject HTML
document.body.innerHTML = testHTML;
// Add class to <body> element and verify
document.body.classList.add('foo');
// Test HTML
expect(document.body.getAttribute('class')).toEqual('foo');
expect(document.body.textContent).toMatch(/Test/);
expect(document.querySelectorAll('p')).toHaveLength(1);
expect(document.querySelector('p').textContent).toBe(testText);
expect(document.querySelector('table')).toBeNull();
});
});