TypeScript Unit Testing

From Chorke Wiki
Revision as of 04:16, 23 May 2019 by Shahed (talk | contribs)
Jump to navigation Jump to search
mkdir -p jasmine_chai_mocha/src
cd jasmine_chai_mocha
npm init
# mocha -r ts-node/register src/**/*.spec.ts
# https://github.com/chorkeinc/chorke-type-cki.js.git
# chorke js
# MIT
npm install chai mocha ts-node @types/chai @types/mocha --save-dev
vim src/hello_world.ts
vim src/hello_world.spec.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_chai_mocha",
  "version": "1.0.0",
  "description": "Chorke Typescirpt Unit 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