[test] Adding tests for the new middleware api's
[minor] Throw an error when the supplied middleware isn't a function