adding back docs

This commit is contained in:
Ken
2019-02-22 20:25:09 -08:00
parent 78368cdf39
commit f70417f6ae
166 changed files with 4344 additions and 516 deletions

View File

@@ -4,5 +4,5 @@
For this step, we look at unit testing. Run
<pre>npm test</pre>
in the command line.
<script type="text/javascript" src="../../step2-04/demo/step2-04/demo.js"></script></body>
<script src="../../step2-04/demo/step2-04/demo.js"></script></body>
</html>

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;
}

View File

@@ -94,7 +94,19 @@
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getCount\", function() { return getCount; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"increment\", function() { return increment; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"decrement\", function() { return decrement; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"square\", function() { return square; });\nvar counter = 0;\nfunction getCount() {\n return counter;\n}\nfunction increment() {\n return ++counter;\n}\nfunction decrement() {\n return --counter;\n}\nfunction square(x) {\n return x * x;\n}\n\n\n//# sourceURL=webpack:///./step2-04/demo/src/index.ts?");
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"getCount\", function() { return getCount; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"increment\", function() { return increment; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"decrement\", function() { return decrement; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"square\", function() { return square; });\n/* harmony import */ var _multiply__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./multiply */ \"./step2-04/demo/src/multiply.ts\");\n\nvar counter = 0;\nfunction getCount() {\n return counter;\n}\nfunction increment() {\n return ++counter;\n}\nfunction decrement() {\n return --counter;\n}\nfunction square(x) {\n return Object(_multiply__WEBPACK_IMPORTED_MODULE_0__[\"multiply\"])(x, x);\n}\n\n\n//# sourceURL=webpack:///./step2-04/demo/src/index.ts?");
/***/ }),
/***/ "./step2-04/demo/src/multiply.ts":
/*!***************************************!*\
!*** ./step2-04/demo/src/multiply.ts ***!
\***************************************/
/*! exports provided: multiply */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"multiply\", function() { return multiply; });\nfunction multiply(x, y) {\n return x * y;\n}\n\n\n//# sourceURL=webpack:///./step2-04/demo/src/multiply.ts?");
/***/ })