From fc33d4868a1dbaddb475a0636e0b47c9ef6bdf42 Mon Sep 17 00:00:00 2001
From: alfonsoruiz <1800ruiz@gmail.com>
Date: Sun, 12 Apr 2020 18:20:14 -0700
Subject: [PATCH] updated syntax to es6
---
example/adder-test.html | 20 +++++-----
tinytest.js | 87 +++++++++++++++++++++--------------------
2 files changed, 53 insertions(+), 54 deletions(-)
diff --git a/example/adder-test.html b/example/adder-test.html
index 040f155..8608810 100644
--- a/example/adder-test.html
+++ b/example/adder-test.html
@@ -1,16 +1,14 @@
diff --git a/tinytest.js b/tinytest.js
index 183d0eb..4140fda 100644
--- a/tinytest.js
+++ b/tinytest.js
@@ -38,54 +38,55 @@
* MIT License. See https://github.com/joewalnes/jstinytest/
*/
const TinyTest = {
+ run(tests) {
+ let failures = 0;
- run: function(tests) {
- let failures = 0;
- for (let testName in tests) {
- let testAction = tests[testName];
- try {
- testAction();
- console.log('Test:', testName, 'OK');
- } catch (e) {
- failures++;
- console.error('Test:', testName, 'FAILED', e);
- console.error(e.stack);
- }
- }
- setTimeout(function() { // Give document a chance to complete
- if (window.document && document.body) {
- document.body.style.backgroundColor = (failures == 0 ? '#99ff99' : '#ff9999');
- }
- }, 0);
- },
+ for (const testName in tests) {
+ const testAction = tests[testName];
- fail: function(msg) {
- throw new Error('fail(): ' + msg);
- },
+ try {
+ testAction();
+ console.log(`Tests: ${testName} OK`);
+ } catch (e) {
+ failures++;
- assert: function(value, msg) {
- if (!value) {
- throw new Error('assert(): ' + msg);
- }
- },
+ console.error(`Test: ${testName} FAILED`, e);
+ console.error(e.stack);
+ }
+ }
- assertEquals: function(expected, actual) {
- if (expected != actual) {
- throw new Error('assertEquals() "' + expected + '" != "' + actual + '"');
- }
- },
+ document.addEventListener('DOMContentLoaded', function () {
+ document.body.style.backgroundColor =
+ failures == 0 ? '#99ff99' : '#ff9999';
+ });
+ },
- assertStrictEquals: function(expected, actual) {
- if (expected !== actual) {
- throw new Error('assertStrictEquals() "' + expected + '" !== "' + actual + '"');
- }
- },
+ fail(msg) {
+ throw new Error(`fail(): ${msg}`);
+ },
+ assert(value, msg) {
+ if (!value) {
+ throw new Error(`assert: ${msg}`);
+ }
+ },
+
+ assertEquals(expected, actual) {
+ if (expected != actual) {
+ throw new Error(`assertEquals() ${expected} != ${actual}`);
+ }
+ },
+
+ assertStrictEquals(expected, actual) {
+ if (expected !== actual) {
+ throw new Error(`assertsStrictEquals() ${expected} !== ${actual}`);
+ }
+ },
};
-const fail = TinyTest.fail,
- assert = TinyTest.assert,
- assertEquals = TinyTest.assertEquals,
- eq = TinyTest.assertEquals, // alias for assertEquals
- assertStrictEquals = TinyTest.assertStrictEquals,
- tests = TinyTest.run;
+const fail = TinyTest.fail,
+ assert = TinyTest.assert,
+ assertEquals = TinyTest.assertEquals,
+ eq = TinyTest.assertEquals, // alias for assertEquals
+ assertStrictEquals = TinyTest.assertStrictEquals,
+ tests = TinyTest.run;