1

I am very new to unit testing and I am getting this really weird error when running Grunt Test.

TypeError: 'undefined' is not an object (evaluating '$websocketBackend.mock')


Error: [$injector:modulerr] Failed to instantiate module myApp due to:

Error: [$injector:unpr] Unknown provider: $routeProvider

spec.js

    describe('test d3mapping websocket', function () {
        var testScope, $controller, $websocketBackend;
        //
        //beforeEach(function() {
        //    module('myApp');
        //    module('ngWebSocket', 'ngWebSocketMock');
        //    inject(function(_$controller_, $rootScope, _$websocketBackend_) {
        //        $controller = _$controller_;
        //        testScope = $rootScope.$new();
        //
        //        $websocketBackend = _$websocketBackend_;
        //
        //    });
        //});

        describe('response', function() {

            beforeEach(function() {
                module('myApp');
                module('ngWebSocket', 'ngWebSocketMock');
                inject(function(_$controller_, $rootScope, _$websocketBackend_) {
                    $controller = _$controller_;
                    testScope = $rootScope.$new();

                    $websocketBackend = _$websocketBackend_;
                });
                $controller('MainCtrl', {
                    $scope: testScope
                });
            });

            it('should send/receive json',
                function() {
                    $websocketBackend.mock();
//server url omitted
                    $websocketBackend.expectConnect("ws://server");
                    $websocketBackend.expectSend(JSON.stringify('{"nodes":[{"name":"A6EBL","group":2,"size":5},{"name":"GBYGC","group":2,"size":5},{"name":"KORD","group":1,"size":10},{"name":"EGLL","group":1,"size":10},{"name":"DNMM","group":1,"size":10}],"links":[{"source":2,"target":1,"value":1},{"source":3,"target":1,"value":1},{"source":3,"target":1,"value":1},{"source":2,"target":1,"value":1},{"source":4,"target":1,"value":1},{"source":3,"target":1,"value":1}]}'));
                }
            );
        });
    });

    // test svg


    describe('Test D3.js with jasmine ', function () {
        var testScope;

        beforeEach(function () {

            module('myApp');
            inject(function ($controller, $rootScope) {
                testScope = $rootScope.$new();
                $controller('MainCtrl', {
                    $scope: testScope
                });
            });
        });



        describe('the svg', function () {
            it('should be created', function () {
                expect(getSvg()).not.toBeNull();
            });
        });

        function getSvg() {
            return document.getElementsByTagName('svg');
        }

    });

Any suggestions would help

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
user2402107
  • 913
  • 5
  • 22
  • 43

1 Answers1

0

It's interesting that Angular can't determine $webSocketBackend.mock or $routeProvider. My guess is that one of your dependencies failed to be injected, and is now causing problems when Angular goes to use the injected dependencies.

Just a guess - but, to reference a similar Stack Overflow question Failed to instantiate module [$injector:unpr] Unknown provider: $routeProvider

Does your controller have access to both $routeProvider and $webSocketBackend?

The ngRoute module is no longer part of the core angular.js file. If you are continuing to use $routeProvider then you will now need to include angular-route.js in your HTML:

Community
  • 1
  • 1
Alex Johnson
  • 1,504
  • 13
  • 20