diff --git a/step2-04/README.md b/step2-04/README.md index e1e3102..d9dd1d8 100644 --- a/step2-04/README.md +++ b/step2-04/README.md @@ -129,18 +129,16 @@ Note how tests are re-run when either test files or source files under `src` are # Exercise +Start the test runner by running `npm test` in the root of the `frontend-bootcamp` folder. + ## Basic testing -1. Run the tests by running `npm test` at the root of the bootcamp project +1. Look at `exercise/src/stack.ts` for a sample implementation of a stack -2. Look at `exercise/src/stack.ts` for a sample implementation of a stack - -3. Follow the instructions inside `stack.spec.ts` file to complete the two tests +2. Follow the instructions inside `stack.spec.ts` file to complete the two tests ## Enzyme Testing 1. Open up `exercise/src/TestMe.spec.tsx` -2. Fill in the blank for the missing test using `enzyme` concepts introduced from the demo - -3. Run tests with `npm test` +2. Fill in the test using Enzyme concepts introduced in the demo diff --git a/step2-04/exercise/src/stack.spec.ts b/step2-04/exercise/src/stack.spec.ts index 8b89b72..388f261 100644 --- a/step2-04/exercise/src/stack.spec.ts +++ b/step2-04/exercise/src/stack.spec.ts @@ -1,15 +1,17 @@ -describe('stack', () => { +// Import the stack here + +describe('Stack', () => { it('should push item to the top of the stack', () => { // implement test here: - // 1. require the stack - // 2. create stack push calls to place some items in the stack - // 3. write assertions via the expect() API + // 1. Create a stack instance + // 2. Use stack push calls to add some items to the stack + // 3. Write assertions via the expect() API }); it('should pop the item from the top of stack', () => { // implement test here: - // 1. require the stack - // 2. create stack push calls to place some items in the stack + // 1. Create a stack instance + // 2. Use stack push calls to add some items to the stack // 3. pop a few items off the stack // 4. write assertions via the expect() API }); diff --git a/step2-04/exercise/src/stack.ts b/step2-04/exercise/src/stack.ts index 267a771..7f62d2d 100644 --- a/step2-04/exercise/src/stack.ts +++ b/step2-04/exercise/src/stack.ts @@ -1,13 +1,27 @@ export class Stack { private _items: T[] = []; + /** Add an item to the top of the stack. */ push(item: T) { this._items.push(item); } + /** Remove the top item from the stack and return it. */ pop(): T { if (this._items.length > 0) { return this._items.pop(); } } + + /** Return the top item from the stack without removing it. */ + peek(): T { + if (this._items.length > 0) { + return this._items[this._items.length - 1]; + } + } + + /** Get the number of items in the stack/ */ + get count(): number { + return this._items.length; + } }