Skip to content

QinisoM/ts-mocking-exercises

 
 

Repository files navigation

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

First 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.6%
  • JavaScript 0.4%