mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
doing step 4 demo notes
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
3
step2-04/demo/src/multiply.ts
Normal file
3
step2-04/demo/src/multiply.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function multiply(x: number, y: number) {
|
||||
return x * y;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user