Skip to content

Commit 79b0227

Browse files
authored
Create assert.js
1 parent 7a2ae53 commit 79b0227

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Documentation/Test/assert.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function assertEqual(actual, expected, message){
2+
if(actual !== expected){
3+
message = ((typeof message != "undefined")? message+" ":"") + "Assertion failed. Expected "+((typeof expected == "string")?"\"":"")+ expected +((typeof expected == "string")?"\"":"")+ " instead got "+((typeof actual == "string")?"\"":"")+ actual +((typeof actual == "string")?"\"":"");
4+
console.error(message);
5+
}else console.log("%cTest passed. "+((typeof actual == "string")?"\"":"")+ actual +((typeof actual == "string")?"\"":"")+ " === " +((typeof expected == "string")?"\"":"")+ expected +((typeof expected == "string")?"\"":""), "color: green;");
6+
}
7+
8+
function assertDeepEqual(actual, expected, message){
9+
if(JSON.stringify(actual) !== JSON.stringify(expected)){
10+
message = ((typeof message != "undefined")? message+" ":"") + "Assertion failed. Expected " + ((typeof expected == "string")?"\"":"") + JSON.stringify(expected) + ((typeof expected == "string")?"\"":"") + " instead got " + ((typeof actual == "string")?"\"":"") + JSON.stringify(actual) +((typeof actual == "string")?"\"":"");
11+
console.error(message);
12+
}else console.log("%cTest passed. "+((typeof actual == "string")?"\"":"")+ JSON.stringify(actual) +((typeof actual == "string")?"\"":"")+ " === " +((typeof expected == "string")?"\"":"")+ JSON.stringify(expected) +((typeof expected == "string")?"\"":""), "color: green;");
13+
}

0 commit comments

Comments
 (0)