TypeScript Unit Testing

From Chorke Wiki
Jump to navigation Jump to search
mkdir -p jasmine_mocha_chai/src
cd jasmine_mocha_chai
npm init
# Chorke Academia TUnit Test
# mocha -r ts-node/register src/**/*.spec.ts
# https://github.com/chorkeinc/chorke-type-cki.js.git
# chorke academia tunit ts js
# Chorke Academia, Inc
# MIT
npm install chai mocha ts-node @types/chai @types/mocha --save-dev
vim src/hello_world.spec.ts
vim src/hello_world.ts
npm run test
npm install

src/hello_world.ts

//src/hello_world.ts
export const hello = () => 'Hello world!';

src/hello_world.spec.ts

//src/hello_world.spec.ts
import { hello } from './hello_world';
import { expect } from 'chai';
import 'mocha';

describe('Hello function', () => {

  it('should return hello world', () => {
    const result = hello();
    expect(result).to.equal('Hello world!');
  });

});

package.json

{
  "name": "jasmine_mocha_chai",
  "version": "1.0.0",
  "description": "Chorke Academia TUnit Test",
  "main": "index.js",
  "dependencies": {},
  "devDependencies": {
    "@types/chai": "^4.1.7",
    "@types/mocha": "^5.2.6",
    "chai": "^4.2.0",
    "mocha": "^6.1.4",
    "ts-node": "^8.1.0",
    "typescript": "^2.0.9"
  },
  "scripts": {
    "test": "mocha -r ts-node/register src/**/*.spec.ts"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/chorkeinc/chorke-type-cki.js.git"
  },
  "keywords": [
    "chorke",
    "js"
  ],
  "author": "Chorke Academia, Inc",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/chorkeinc/chorke-type-cki.js/issues"
  },
  "homepage": "https://github.com/chorkeinc/chorke-type-cki.js#readme"
}

References