Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngMidwayTester.visit never executes callback #9

Open
pbtura opened this issue Nov 1, 2013 · 3 comments
Open

ngMidwayTester.visit never executes callback #9

pbtura opened this issue Nov 1, 2013 · 3 comments

Comments

@pbtura
Copy link

pbtura commented Nov 1, 2013

I tried following the example from the docks and everything looked fine initially. When I dug a little deeper though I noticed a problem. The 'passing' test is actually a false negative. The callback function supplied as the second argument of the call to 'tester.visit' never actually executes, thus none of the assertions are actually tested.

Not sure if the problem is something in my setup or if it is a bug. Here is my spec, the only change I made was adding some logging:

angular.module('myModule', ['ngRoute'])
    .config(function($routeProvider) {
        $routeProvider.when('/home', {
            template : 'welcome to {{ title }}',
            controller : 'HomeCtrl'
        });
    })
    .controller('HomeCtrl', function($scope) {
        $scope.title = 'my home page foo';
    });

//this test spec uses mocha since it has nice support for async testing...
describe('my test spec', function() {
    var tester;
    beforeEach(function() {
        tester = ngMidwayTester('myModule', {
            template : '<div>' +
                '  <h1>hello</h1>' +
                '  <div id="view-container">' +
                '    <div ng-view></div>' +
                '  </div>' +
                '</div>'
        });
    });

    afterEach(function() {
        tester.destroy();
        tester = null;
    });

    it('should have a working home page', function(done) {

        console.log(['running home test']);
        tester.visit('/home', function() {
            console.log(['visited home']);
            expect("abc").toBe("xyz");
            expect(tester.path()).to.equal('/home');
            expect(tester.viewElement().html()).to.contain('welcome to my home page');

            var scope = tester.viewScope();
            expect(scope.title).to.equal('my home page');
            done();
        });

    });
});
@pbtura
Copy link
Author

pbtura commented Nov 1, 2013

After some additional hair pulling, I figured out the issue. The visit call is asynchronous and requires mocha to work correctly. Mabey it would be a good idea to make the comment a little more clear. An example of how to do the same thing with jasmine might be good as well.

@Galaf
Copy link

Galaf commented Aug 26, 2015

Could you please post the solution, @pbtura ?
I can't get it to work either.

@pbtura
Copy link
Author

pbtura commented Aug 26, 2015

Unfortunately, I don't think I am using midway tester anymore so I don't have an example. I seem to recall that I need to use mocha rather than jasmine as a dependency (probably why I moved away from this solution). To be honest, this project is pretty old and there have been some significant changes to angular and karma since it was last updated. Even if I had an example of what I did, it probably would not work anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants