Files
  • index.js
  • doSomething.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const assert = require('assert');
const { doSomething } = require('./doSomething.js')

const tests = {
  'doSomething should be a function' : function () {
    const actual = typeof doSomething;
    assert(actual === "function", `Expected ${actual} to be "function"`);
  }, 
  'doSomething should return a number' : function () {
    const actual = doSomething(1);
    assert(isNaN(actual), 'Number not returned');
  },
  'doSomething should double the value until result above 10' : function () {
    const belowTenResult = doSomething(1);
    assert.equal(belowTenResult, 16);

    const aboveTenResult = doSomething(15);
    assert.equal(aboveTenResult, 30);
  },
  'doSomething should handle special edge case for some reason' : function () {
    const actual = doSomething(3);
    assert.equal(actual, '12was 3');
  }
}

let exitCode = 0;
Object.keys(tests).forEach((test) => {
  try {
    tests[test]()
    console.log(`Passed: '${test}'`)
  } catch (e) {
    exitCode = 1
    console.error('\x1b[1m', `Failed: '${test}' - ${e.message}`, '\x1b[0m')
  }
})

process.exit(exitCode)
node v9.7.1 linux/amd64