@squeep/test-helper
v3.1.0
Published
Common modules and helpers for Squeep Framework Applications unit testing.
Readme
Test Helper
Helpers for writing tests which use various Squeep packages, or other test conveniences.
Squeep Structured Logger
Provides a simple console-like logger object with sinon spies attached.
Actual console output can be enabled by setting the VERBOSE_TESTS environment variable, or passing a flag to the stub constructor.
Usage
const { describe, it, beforeEach, afterEach } = require('node:test');
const { StubLogger } = require('@squeep/test-helper');
const assert = require('node:assert');
const sinon = require('sinon');
class App {
constructor(logger) {
this.logger = logger;
}
doAThing() {
this.logger.error('doAThing', 'oh no', { data: true });
}
}
describe('App Test', function () {
let app, logger;
beforeEach(function () {
logger = new StubLogger(sinon);
app = new App(logger);
});
afterEach(function () {
sinon.restore();
});
it('uses stubs', function () {
app.doAThing();
assert(logger.error.called);
});
});html-validate
Provides convenience wrapper for validating HTML in tests.
Usage
const { describe, it } = require('node:test');
const assert = require('node:assert');
const { HtmlValidate } = require('html-validate');
const { makeHtmlLint, LintError } = require('../lib/lint-html');
const StubLogger = require('../lib/stub-logger');
const sinon = require('sinon');
const stubLogger = new StubLogger(sinon);
const htmlLint = makeHtmlLint(stubLogger, new HtmlValidate());
describe('lint html', function () {
it('passes', async function () {
await htmlLint(`<html lang="en">
<head>
<title>Title</title>
</head>
<body>
</body>
</html>`);
});
it('fails', async function () {
await assert.rejects(htmlLint('<html>dsfjkl'), LintError);
});
});