Skip to content

Instantly share code, notes, and snippets.

@HudsonAfonso
Forked from up1/HelloWorld.ts
Created July 28, 2019 13:36
Show Gist options
  • Save HudsonAfonso/f89c9f8a2bb50ae035827729b3603438 to your computer and use it in GitHub Desktop.
Save HudsonAfonso/f89c9f8a2bb50ae035827729b3603438 to your computer and use it in GitHub Desktop.
TDD with TypeScript
export class HelloWorld {
public sayHi(name: string): string {
return "Hi, " + name;
}
}
import "mocha";
import "should";
import { HelloWorld } from "../src/HelloWorld";
describe("HelloWorld", () => {
let tested: HelloWorld;
beforeEach(() => tested = new HelloWorld());
describe("Say hi", () => {
it("should say Hi, somkiat", () => {
const result = tested.sayHi("somkiat");
const expected = "Hi, somkiat";
result.should.be.equal(expected);
});
it("should say Hi, somkiat2", () => {
const result = tested.sayHi("somkiat2");
const expected = "Hi, somkiat2";
result.should.be.equal(expected);
});
});
});
{
"name": "helloworld",
"version": "1.0.0",
"description": "TDD with TypeScript",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"devDependencies": {
"@types/mocha": "2.2.39",
"@types/should": "8.1.30",
"mocha": "3.2.0",
"should": "11.2.0",
"typescript": "2.1.6"
}
}
{
"name": "helloworld",
"version": "1.0.0",
"description": "TDD with TypeScript",
"main": "index.js",
"scripts": {
"build": "tsc",
"pretest": "npm run build",
"test": "mocha dist/tests"
}
...
}
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": false,
"experimentalDecorators": true,
"sourceMap": true,
"outDir": "dist"
},
"exclude": [
"dist",
"node_modules"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment