Instead of calling Date.now() or opening a database connection itself, the function takes it as a parameter. A test passes a fake one and gets a deterministic result.
Dependency injection
Passing dependencies (like time or a database) in from outside instead of creating them inside the function.