You need to declare the $compile and $rootScope properties outside this function, probably best at the start of the describe block.