@@ -5,9 +5,9 @@ const deepEqual = require('deep-equal');
55const beforeEachStack = [ [ ] ] ;
66// Runs every beforeEach callback in the stack
77const runEveryBeforeEach = ( ) => {
8- beforeEachStack . forEach ( level => level . forEach ( cb => cb ( ) ) ) ;
8+ beforeEachStack . forEach ( ( level ) => level . forEach ( ( cb ) => cb ( ) ) ) ;
99} ;
10- const beforeEach = cb => {
10+ const beforeEach = ( cb ) => {
1111 beforeEachStack [ beforeEachStack . length - 1 ] . push ( cb ) ;
1212} ;
1313
@@ -16,13 +16,31 @@ const summary = { success: true, testResults: [] };
1616let tempResult = { logs : '' } ;
1717
1818let consoleLogCache = console . log ;
19- console . log = input => {
19+ console . log = ( input ) => {
2020 tempResult . logs =
2121 tempResult . logs === '' ? input + '' : tempResult . logs + '\n' + input ;
2222} ;
2323
24+ /**
25+ We are overloading this function. It can be used with either 2 or 3 params
26+ * using it with 2 params means the first param is the `title` and the second is the `callback`
27+ * using it with 3 params means the first param is the test `input`, the second is the `title` and the third is the `callback`
28+ */
2429// Declares a test unit
25- const test = ( input , title , cb ) => {
30+ const test = ( param1 , param2 , param3 ) => {
31+ let input ;
32+ let title ;
33+ let cb ;
34+ // This check sets the function up for overloading the params. If the second param is a function, we ignore the third param
35+ // if the second param is not a function, we expect 3 params to be provided.
36+ if ( typeof param2 == 'function' ) {
37+ title = param1 ;
38+ cb = param2 ;
39+ } else {
40+ input = param1 ;
41+ title = param2 ;
42+ cb = param3 ;
43+ }
2644 runEveryBeforeEach ( ) ;
2745 tempResult = { logs : '' } ;
2846 tempResult . input = input ;
0 commit comments