Category: Unit Testing

  • How to mock the Date to keep date-based unit tests predictable

    How to mock the Date to keep date-based unit tests predictable

    When unit testing functions that use the Date.now() function, you’ll need to lock down the value it returns – otherwise, your unit tests will only ever run successfully on the day (or even the minute!) that you run them. This article shows how you can override Date.now() to make it return a predictable value. Step […]

  • How to unit-test a directive with templateURL

    How to unit-test a directive with templateURL

    It’s best practice to place the HTML of a directive’s partial within its own file, and reference it in the directive’s definition object via the templateUrl property. However, this causes problems in testing, as most testing frameworks provide no access to the local file. This article shows you how to get around this limitation, and […]