
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Learn to use Jest with TypeScript and Node.js for unit and integration tests, covering test structure, matchers, parameterized tests, test doubles, debugging, coverage, and TDD.
Install NodeJS (version 18 or newer) and set up a code editor, with Visual Studio Code recommended, then use a terminal for running commands in this course.
Define software tests as code that runs other code to make assertions, and present unit tests as requirements, noting unit, integration, and end-to-end tests for peace of mind.
Install tools and dive into Jest basics for TypeScript, set up a Jest and TypeScript project, structure unit tests, and introduce assertions and matchers.
Jest is a JavaScript and TypeScript testing framework and test runner with global helpers like describe, test, and expect. It provides an assertion library, matchers, and strong TypeScript support.
Initialize a Node project, install TypeScript and Jest as development dependencies, configure Jest for TypeScript, and create a simple utils function with unit tests using describe and test.
Adopt the universal triple-a structure for unit tests: arrange, act, and assert, using a system under test to improve readability and consistency across languages and frameworks.
Explore jest assertions and matchers for TypeScript and node, learning how to compare actual vs expected values, use toBe for primitives and toEqual for objects, and test strings and arrays.
Create meaningful unit tests by organizing into separate describe blocks and test suites, ensuring independent tests for get string info, verifying length, lower case, upper case, characters, and extra info.
Learn how to use parameterized tests in Jest to run multiple inputs with one test, using each to supply input and expected values, reducing redundancy and validating outputs.
Move into intermediate topics in Jest and TypeScript, learn first principles for writing proper unit tests with hooks, error testing, aliases, and code coverage in VS Code.
Explore the F.I.R.S.T. principles of unit testing—fast, independent, repeatable, self validating, and thorough—while learning how mocks, teardown, and coverage relate to reliable tests.
Learn how jest hooks enable setup and teardown, following AAA, to keep tests independent and reduce duplication with before each and after each in a string utils uppercases input.
Learn how to test for errors in Jest using a wrapper function and toThrow for an invalid argument. Compare direct calls, try-catch blocks, and done callbacks for robust error validation.
Learn how to use Jest test properties like only, skip, concurrent, and to do, plus aliases for it and test, and enable watch mode for continuous test feedback.
Learn to debug unit tests in VS Code with a tailored launch.json, run just the current file, set breakpoints, and inspect variables in a node Jest environment.
Learn to configure code coverage in a Jest project by enabling collectCoverage and collectCoverageFrom, running npm test to produce an HTML report, and using Istanbul ignore to exclude code.
Explore test driven development with Jest in a TypeScript context by building a password checker and practicing TDD through writing and validating tests.
Explore test driven development by writing tests first to define requirements, trigger red tests, and implement to turn them green within a red-green-blue cycle.
Practice coding katas to improve test driven development with a password checker. Work through three iterations, assessing invalidity reasons and later adding number checks for admin passwords.
Set up a pass checker folder in a TypeScript project, configure jest test paths and coverage to run only within this folder, and prepare a password checker class and tests.
Drive test-driven development by writing tests and implementing a password checker in TypeScript with Jest for Node.js, enforcing eight-character length and the inclusion of uppercase and lowercase letters.
Refine the pass checker to return specific password reasons via a check result interface and a password errors enum, and refactor tests to validate reasons and overall validity.
Refactor the password checker by moving length, uppercase, and lowercase checks into private methods, add an admin password check for a number, and verify with unit tests using Jest.
Explore test doubles—stubs, fakes, mocks, and spies—and learn how to mock modules in Jest and TypeScript to manage the complexity of production code.
Explore what test doubles are, why tests need them, and how Jest uses mocks and spies to replace databases and other slow dependencies.
Explore stubs as incomplete objects for tests, set up a doubles folder, and implement a calculate complexity function for a string info object using TypeScript and test utils.
Learn how fakes provide simplified working implementations in unit testing, illustrated by an uppercase function with a background logger callback, and understand how test coverage can mislead without mocks.
Explore creating handmade mocks to track callback arguments and call count, then compare with library mocks, and learn to reset mocks after each test to ensure independence.
Learn how spies differ from mocks and preserve original functionality, spy on public methods, and track calls. Replace a method's implementation for testing the system under test.
Mock modules at the module level using just mock in Jest, replace whole module functionality, preserve other functions with require actual, and mock uuid for deterministic tests.
Delve into test doubles and mocks in unit testing with TypeScript and Node.js using Jest, comparing Chicago and London styles and defining a unit as a requirement to guide tests.
Explore a simple reservation server with registration, login, and token-based authentication, backed by an in-memory database, enabling create, view, update, and delete reservations, tested with Jest for TypeScript applications.
Install and launch a simple Node.js TypeScript server, configure a start script, and test authentication and reservations using rest clients, as you prepare for unit tests and heavy mocking.
Test an in-memory TypeScript database with Jest by validating insert, get by ID, find by filter, update, delete, and get all operations, using a mocked random ID generator.
Learn to unit test a consumer class that instantiates its own database by mocking the database path with Jest in TypeScript, covering user credentials, session tokens, and reservations.
Inject mocks into the register handler via constructor to simplify unit testing of post requests. Mock request, response, and authorizer, spy on the body, and verify user id with Jest.
Explore unit testing patterns for TypeScript and Node.js servers using Jest, covering register, login, and reservations handlers, including validation of request bodies, authorization, and error handling.
Learn how to test event-based Node.js code using a get request body function that parses incoming message events and handles data, error, and end events with Jest.
Set up server tests for a TypeScript and Node.js project using Jest, mock the http createServer and request/response, structure mocks, and assert authorizer and reservations data access are instantiated.
Debug server tests in Jest for TypeScript and Node; fix asynchronous timing, verify mocks and response end, and use logs and breakpoints to solve failures.
Finalize server class tests using prototype spies to verify register, login, and reservation requests, with mocks for request, response, authorizer, and data access, including error handling and stopping the server.
Finish tests for the authorizer and id generator, showing token validation via session token data access and user credentials data access, with mocks and constructor objects, achieving 100% coverage.
Explore the advantages and disadvantages of heavy mock testing with Jest, highlighting class isolation and the maintenance burden of tightly coupled tests.
Adopt a low mock testing approach for TypeScript and Node.js with Jest, building request and response wrappers to test server interactions while mocking only the database.
Create request and response test wrappers to enable end-to-end server tests with low mock testing, asserting http status, headers, and body.
Set up a unit test for the register route with a mocked database and fake server; verify new user returns a userId and HTTP 201, using spies and timing fixes.
Finish the register, login, and reservations tests using low-code tests in TypeScript with Jest; validate bad requests, unauthorized access, and non-supported methods, then review code coverage.
Compare low mock testing with high mocking testing, noting that low mocks are easier to read and maintain but may miss edge cases and complicate CI/CD.
Explore integration tests, distinguish them from unit tests, and practice using our sample application to understand how integration tests work.
Learn how integration tests verify multiple components together, minimize mocking, and run tests against realistic deployments—from local to production—by launching the app, making user-like requests, and validating database interactions.
Set up integration tests with an http client, using node fetch or the standard http module, start a real server, and register a new user to verify creation in jest.
Write and run integration tests for login and reservations, capture a token, use it in authorization header for requests, and verify create, read, update, and delete operations with status codes.
Explore environment variables, manage multiple test configurations, and try snapshot testing, plus custom measures and the NodeJS native test runner.
Load custom test configurations for integration tests by using setup files to inject environment variables such as host and port, enabling tests to connect to a test server or database.
Create separate jest configurations for unit and integration tests, link them with npm scripts, and target tests in server app folders to run distinct test suites from different folders.
Learn how snapshot testing simplifies validating large objects and generated configurations by creating, storing, and matching snapshots in integration tests, great for UI components like React and JSON configurations.
Learn to write custom matchers in jest by extending expect with your own measures for a reservation object, including validation of id and user, and integrating TypeScript types.
Explore the experimental built-in node.js test runner and run JavaScript and TypeScript tests using describe, test, and assert, with node:test usage and type definitions.
Explore popular JavaScript and TypeScript testing frameworks, including Jest, Mocha, and Vitest, and learn how under-the-hood similarities let you switch between tools while using mocks, assertions, and runners.
Set up unit testing for React and TypeScript projects with Create React Library, recap React states, properties, and generics, and test user interactions and asynchronous updates in a login form.
Set up a simple React TypeScript app from scratch with npx create-react-app, configure testing with Jest and React Testing Library, and clean the project to focus on basics.
Master TypeScript generics, and understand how props and state drive rendering in React components through practical examples of parent and child components.
Test a basic React login form using a mocked login service to simulate credentials, validating the login component's handling of token setting, success and failure messages, and asynchronous behavior.
Write React TypeScript tests for a login component, render it with mocks using React Testing Library, and verify the initial state, main div role, and input elements.
Learn to query elements in rendered React components using React testing library, including setup with beforeEach, a setup function, test IDs, roles, and document queries.
Test user interaction on a login form by simulating login button clicks with fire event or user event, validating the 'username and password required' message, including asynchronous updates with act.
Mock the login service and test asynchronous updates in a login form using fire events or user events, then await find by test id to verify login mock calls.
A must have skill for senior developers
Typescript is getting more and more popularity and it is a required skill for many IT jobs. It's key feature is type safety, thus preventing bugs.
But yes another skill is very important for any programming job: unit testing. Combining these two techniques will result in solid, robust and bug free code.
This course will go beyond the basics of unit testing and teach you all you need to write real world, complex testing suites for NodeJs and Typescript applications using the most popular JavaScript testing library: Jest.
Using Jest as an unit testing library provides many advantages:
Unitary unit testing library for running and structuring tests
Extensive mocking, stubbing and spying capabilities
Powerful matchers to create simple to read tests
Jest ships as one unitary NPM package
Jest is the default choice for TypeScript React projects
Why unit testing NodeJs apps?
Unit testing usually adds a lot to a code base, two or tree times in some cases. This also means that a lot of time needs to be invested in writing and setting up tests. But all this effort pays of: time, effort and headache of fixing bugs can be used for more fun activities.
What you will get from this course:
setup NodeJs and Typescript projects from scratch
implement unit testing with Jest
learn about unit testing configuration with parameters like: roots, transform, testRegex or verbose
learn about Jest test suites structure: describe with value, test, descriptions, hooks like beforeEach
basic and advanced assertions, comparing primitive types, objects or even errors
instantiating test double objects like mocks, stubs, spies or fakes.
write complex mock objects which can be used with "strange" JavaScript libraries.
inject doubles: directly inside the constructor, over the module or even using the objects prototype
learn about deep mocks and matchers to make your tests even better
integration tests for a NodeJs server application
Conditionally and asynchronously skip tests
Dedicated sections on unit testing mocks:
Jest mocks, spies
How to use stubs
London/Chicago testing approach, with the advantages and disadvantages of each one
In this course you will learn how to use Test Driven Development (TDD):
Analyze the advantages of TDD
Hands-on practice with a great coding kata: password checker
Separate section on Jest Integration tests for Rest APIs:
learn how to setup integration tests
learn the difference between integration tests and unit tests
write integration tests for a Rest API with Jest
Dedicated section on Jest React unit testing:
How to test for React components with Jest
How to test React async code
How to debug React Typescript apps
The examples used in the course follow very high coding guidelines for Typescript, NodeJs and React. Async/await syntax is used for clear and concise code, and of course, you will see how to test asynchronous code, on server, but also in the front end.
Course advantages:
Respect for your time: most of the time of the instructor typing is cut off, the course is focused on unit tests and Jest explanations
Concise: learn only what you need, no fillers to make the course falsely more appealing
Experienced and programming active instructor: a great teacher never looses touch with the industry. This is especially true for software development, where the industry is so dynamic. This helps the instructor stay up to date with the best coding guidelines and present you the challenging parts, not the "hello world"
Organized course structure: six parts, progressive approach, consistent content
Code changes in each lecture on Git with code diffs: this will help you get an concise overview of the lecture and correct in case you missed something
Big font, dark background, fullHD content, this way it is readable even on a small screen or even tablet.
Lifetime access
Certificate of completion to present to your current or prospective employer
Do you want your Typescript or NodeJs code to have the best quality, and your project to be safe?
Enroll and start writing your tests in 10 minutes!