TypeScript Unit Testing

From Chorke Wiki
Revision as of 04:10, 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 install
npm run test

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!');
  });

});

References