Replace `nextTick` with `setImmediate` in tests.

Closes #318.