doing step 4 demo notes

This commit is contained in:
Ken
2019-02-22 15:02:53 -08:00
parent 61f7eb6ce5
commit 79fdc8cd47
8 changed files with 63 additions and 29 deletions

View File

@@ -1,13 +1,20 @@
import { square } from '.';
import { multiply } from './multiply';
// Mocked here by jest for the entire test module file
jest.mock('./multiply');
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 be passing in the multiple two of the same number', () => {
square(5);
// .toBeCalledTimes() and .toBeCalledWith() only work on mocks - we mocked the multiply function from the
expect(multiply).toBeCalledTimes(1);
expect(multiply).toBeCalledWith(5, 5);
});
it('should increment counter', () => {

View File

@@ -1,3 +1,5 @@
import { multiply } from './multiply';
let counter = 0;
export function getCount() {
@@ -13,5 +15,5 @@ export function decrement() {
}
export function square(x: number) {
return x * x;
return multiply(x, x);
}

View File

@@ -0,0 +1,3 @@
export function multiply(x: number, y: number) {
return x * y;
}

View File

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