51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
import StoreTest from './modules/store.spec.js';
|
|
|
|
class Test {
|
|
constructor(root) {
|
|
this.root = root;
|
|
this.tests = [];
|
|
this.pass = 0
|
|
this.fail = 0
|
|
}
|
|
|
|
start() {
|
|
this.defineTests();
|
|
this.tests.forEach((testClass) => {
|
|
this.log(`Testing ${testClass.constructor.name}`);
|
|
testClass.test();
|
|
}
|
|
);
|
|
this.log(`
|
|
|
|
Passed ${this.pass} tests
|
|
Failed ${this.fail} tests
|
|
`);
|
|
}
|
|
|
|
defineTests() {
|
|
this.tests = [
|
|
new StoreTest(this.assert.bind(this)),
|
|
];
|
|
}
|
|
|
|
assert(description, current, expected) {
|
|
const sameType = typeof current === typeof expected;
|
|
const sameValue = JSON.stringify(current) === JSON.stringify(expected);
|
|
let result = '[ERROR]';
|
|
if (sameType && sameValue) {
|
|
this.log(` [PASS] ${description}`);
|
|
this.pass++;
|
|
} else {
|
|
this.log(` [FAIL] ${description}. Expected (${typeof expected}) ${JSON.stringify(expected)}, got (${typeof current}) ${JSON.stringify(current)}`);
|
|
this.fail++;
|
|
}
|
|
}
|
|
|
|
log(text) {
|
|
this.root.insertAdjacentText("beforeend", `${text}\n`);
|
|
}
|
|
}
|
|
|
|
const testSuite = new Test(document.getElementById('root'));
|
|
testSuite.start();
|