added small exercise for jest testing

This commit is contained in:
Ken
2019-02-18 20:59:56 -08:00
parent c5cb0abff8
commit b5c038af9e
10 changed files with 92 additions and 20 deletions

View File

@@ -0,0 +1,32 @@
import { square } from '.';
describe('jest example', () => {
beforeEach(() => {
jest.resetModules();
});
it('should be able to give the square of two numbers', () => {
console.log('test');
expect(square(5)).toBe(25);
});
it('should increment counter', () => {
const { increment } = require('.');
expect(increment()).toBe(1);
});
it('should decrement counter', () => {
const { decrement } = require('.');
expect(decrement()).toBe(-1);
});
it('should retrieve count', () => {
const { decrement, getCount, increment } = require('.');
increment();
increment();
decrement();
increment();
expect(getCount()).toBe(2);
});
});

View File

@@ -0,0 +1,17 @@
let counter = 0;
export function getCount() {
return counter;
}
export function increment() {
return ++counter;
}
export function decrement() {
return --counter;
}
export function square(x: number) {
return x * x;
}

View File

@@ -0,0 +1,14 @@
export type FilterTypes = 'all' | 'active' | 'completed';
export interface TodoItem {
label: string;
completed: boolean;
}
export interface Store {
todos: {
[id: string]: TodoItem;
};
filter: FilterTypes;
}