@ -1,3 +1,4 @@ | |||||
*.map | *.map | ||||
/.vscode/* | /.vscode/* | ||||
/tests/*.js | |||||
/tests/*.js | |||||
node_modules |
@ -0,0 +1,9 @@ | |||||
module.exports = { | |||||
transform: { | |||||
'^.+\\.ts?$': 'ts-jest' | |||||
}, | |||||
testEnvironment: 'node', | |||||
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx|js)$', | |||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] | |||||
}; |
@ -0,0 +1,11 @@ | |||||
{ | |||||
"scripts": { | |||||
"test": "jest" | |||||
}, | |||||
"devDependencies": { | |||||
"@types/jest": "^25.1.3", | |||||
"jest": "^25.1.0", | |||||
"ts-jest": "^25.2.1", | |||||
"typescript": "^3.8.2" | |||||
} | |||||
} |
@ -0,0 +1,28 @@ | |||||
import { descriptiveCounter } from "../descriptiveCounter"; | |||||
describe('descriptiveCounter', function () { | |||||
it('one blankspace', function () { | |||||
let result = descriptiveCounter(" "); | |||||
expect(result).toBe("one blankspace"); | |||||
}); | |||||
it('mixed chars', function () { | |||||
let result = descriptiveCounter(" A "); | |||||
expect(result).toBe("one blankspace & one 'A' & one blankspace"); | |||||
}); | |||||
it('4 blankspaces', function () { | |||||
let result = descriptiveCounter(" "); | |||||
expect(result).toBe("four blankspaces"); | |||||
}); | |||||
it('9 blankspaces', function () { | |||||
let result = descriptiveCounter(" "); | |||||
expect(result).toBe("many blankspaces"); | |||||
}); | |||||
it('2 As', function () { | |||||
let result = descriptiveCounter("AA"); | |||||
expect(result).toBe("two 'A's"); | |||||
}); | |||||
}); |
@ -1,30 +0,0 @@ | |||||
import { descriptiveCounter } from "../descriptiveCounter"; | |||||
import { assert } from "./assert"; | |||||
let testCount: number = 0; | |||||
type StringCallback = (text: string) => string; | |||||
var showUnitTests = true;//window.location.href.indexOf("http") < 0; | |||||
export function testDescriptiveCounter() { | |||||
if (showUnitTests) { | |||||
testCount = 0; | |||||
start(); | |||||
console.log("total tests: " + testCount); | |||||
} | |||||
} | |||||
function start() { | |||||
console.log("=== descriptiveCounter ==="); | |||||
test(descriptiveCounter, "one blankspace", " ", "one blankspace"); | |||||
test(descriptiveCounter, "mixed chars", " A ", "one blankspace & one 'A' & one blankspace"); | |||||
test(descriptiveCounter, "4 blankspaces", " ", "four blankspaces"); | |||||
test(descriptiveCounter, "9 blankspaces", " ", "many blankspaces"); | |||||
test(descriptiveCounter, "2 As", "AA", "two 'A's"); | |||||
} | |||||
function test(func: StringCallback, testName: string, inputs, expected: string) { | |||||
let actual: string = func(inputs); | |||||
assert(testName, expected, actual); | |||||
testCount++; | |||||
} |