Browse Source

use jest

master
g2384 4 years ago
parent
commit
f2acc816b5
6 changed files with 4580 additions and 31 deletions
  1. +2
    -1
      .gitignore
  2. +9
    -0
      jest.config.js
  3. +4530
    -0
      package-lock.json
  4. +11
    -0
      package.json
  5. +28
    -0
      tests/descriptiveCounter.test.ts
  6. +0
    -30
      tests/descriptiveCounterTests.ts

+ 2
- 1
.gitignore View File

@ -1,3 +1,4 @@
*.map
/.vscode/*
/tests/*.js
/tests/*.js
node_modules

+ 9
- 0
jest.config.js View File

@ -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']
};

+ 4530
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 11
- 0
package.json View File

@ -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"
}
}

+ 28
- 0
tests/descriptiveCounter.test.ts View File

@ -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");
});
});

+ 0
- 30
tests/descriptiveCounterTests.ts View File

@ -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++;
}

Loading…
Cancel
Save