Node.js Fundamentals

As a non-blocking programming language with amazing concurrency capabilities, it is no surprise that JavaScript shines just as brightly on the server side as it does in a browser. Whether you are making a build tool, web application or API, the rich JavaScript ecosystem and Node core libraries are by your side.

Node.js Fundamentals

Testing

You may already be using some Node-friendly testing tools and assertion libraries. We will focus mostly on Mocha, a flexible and straightforward testing framework that works equally well for server and client-side code.

  • TestingUnit Tests

    Unit tests are fast, lightweight, and designed to validate algorithmic complexity in isolation. We’ll learn how to write our code in such a way that the trickiest parts are easily unit testable without having to build large numbers of “stubs”.

  • TestingEXERCISE: Unit testing with Mocha

    Build a handlebars helper function that formats a number nicely for analytics dashboards. You must write your unit tests to fulfill these requirements:

    • 23004 should be represented as 23.0K
    • -914 should be represented as -914
    • 1060241 should be represented as 1.1M
  • TestingIntegration Tests

    Integration tests are designed to ensure interfaces or connections between components of your application work properly. We’ll learn how to write tests for two important “interfaces” to any Express app:

    • Ensuring that URLs are handled by the appropriate route,
    • Ensuring that routes pass the expected data to views.
  • TestingEXERCISE: Integration testing with Mocha

    Write an integration tests suite to ensure that the GET /course view is passed the correct data to render its template.

  • TestingAcceptance Tests

    Acceptance tests, sometimes called functional tests, are designed to ensure that critical user workflows work correctly and protect them from regression. Acceptance tests are the closest thing we have to simulating user behavior. They should be designed in such a way that they mimic what users may do. Acceptance tests usually involve starting up the entire app and are considerably slower than unit or acceptance tests. You should have a few of these, but the more you have, the slower your test suite will be.

  • TestingEXERCISE: API acceptance testing with Mocha

    Build acceptance tests for the /api/course JSON Create, Read, Update and Destroy endpoints.

  • TestingEXERCISE: HTML acceptance testing with Mocha

    Build acceptance tests for the /course HTML Create, Read, Update and Destroy endpoints.

  • TestingWrap Up and Recap

    We'll recap everything we have learned throughout the course, and discuss resources for future learning.