wardbell / bardjs

Spec helpers for testing angular v.1.x apps with Mocha, Jasmine and QUnit
MIT License
178 stars 34 forks source link

how to mock scope.$on? #21

Closed crisryantan closed 8 years ago

crisryantan commented 8 years ago

http://stackoverflow.com/questions/33005131/typeerror-undefined-is-not-a-function-evaluating-scope-on

winnemucca commented 8 years ago

Remember $.on is just a listener. similar to $emit and $broadcast. If you are using Jasmine you can spy on it can call through. If you just want to see if it has been called you can do like so

var emitOccur = false;
            $rootScope.$on('$methodsBound', function () {
                emitOccur = true;
            });
            //** $emit occurs on $compile.  Compiling again so listener is set up Need to call
            //compile after emit
            $compile(element)($rootScope);
            $rootScope.$digest(element);

            //expect(emitOccur).toBe(true);
            expect(emitOccur).to.be.true;

I am literally testing this over and over. Let me know if that doesn't work and/or feel free to point me to your issue on stack overflow and I can help you with it there if still having an issue. I am assuming by the date of this you probably fixed it by now.

crisryantan commented 8 years ago

thanks! yes it has been fixed. sorry forgot to close