Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 4.58 KB

README.md

File metadata and controls

78 lines (56 loc) · 4.58 KB

ts-mocking-exercises

The aim of these exercises is to use various mocking techniques to successfully write unit tests for the provided code examples.

Getting started

Frist get the source onto your machine by cloning this repo. Then then run npm i.

Each exercise has it's own implementation and empty ignored tests. Tests have been provided in 3 different frameworks jest, jasmine and mocha + sinon + chai. Jest is configured to run against .spec.ts files and mocha is configured to run against .test.ts files and jasmine is configured to run against .jasmine.ts files.

  • run all tests (mocha, jest and jasmine): npm run test
  • run jest tests: npm run test-jest
  • run mocha tests: npm run test-mocha
  • run jasmine tests: npm run test-jasmine

Exercises

The goal is to complete the empty tests for each exercise. Feel free to use whichever testing/mocking framework you like, you do not need to write the tests for all frameworks.

Remember the tests are all ignored so you will have to unignore them before they'll execute. To do that:

  • for jasmine, change xit( to it(
  • for jest and mocha, change it.skip( to it(

1. Function was called

2. Mock function return value

3. Mock dependency injected into class

4. Mock dependency initialized within class

5. Fake timers

6. Waiting before assertion

7. Using it all together