UT/E2E test with route?

476 views
Skip to first unread message

Xi Shen

unread,
Dec 9, 2012, 9:03:03 AM12/9/12
to ang...@googlegroups.com
Hi,

I am wondering if there's a way to test the route behavior using unit test, or E2E test. I am using Testacular and ngScenario.

I tried "browser().navigateTo('/mytest')", and the in the browser console, I see ngScenario is really trying to load that URl, and got a 404 error, because I did not start my web server. But I think starting my web server won't help here. I want to know if the URL is handled by NG, and if my controller is called, or the "$routeChangeSuccess" event is triggered.

Any idea how to implement this?


Thanks,
David.

Peter Bacon Darwin

unread,
Dec 9, 2012, 9:55:53 AM12/9/12
to ang...@googlegroups.com

E2e tests rely on a host serving up your files. It is end to end after all!

Pete
...from my mobile.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 

Xi Shen

unread,
Dec 9, 2012, 10:09:35 AM12/9/12
to ang...@googlegroups.com
well...that makes sense. ;P

Yevgeniy Valeyev

unread,
Dec 10, 2012, 6:16:09 AM12/10/12
to ang...@googlegroups.com
Is there a way to create a unit test for route? 

воскресенье, 9 декабря 2012 г., 16:55:53 UTC+2 пользователь Peter Bacon Darwin написал:

Peter Bacon Darwin

unread,
Dec 10, 2012, 7:48:07 AM12/10/12
to ang...@googlegroups.com
What is it about the route that you want to test?

Yevgeniy Valeyev

unread,
Dec 10, 2012, 7:56:24 AM12/10/12
to ang...@googlegroups.com
I want to test if router passes params into controller correctly (Such weird task).(in unit test)

понедельник, 10 декабря 2012 г., 14:48:07 UTC+2 пользователь Peter Bacon Darwin написал:

Pawel Kozlowski

unread,
Dec 10, 2012, 7:59:25 AM12/10/12
to ang...@googlegroups.com
Hi!

On Mon, Dec 10, 2012 at 1:56 PM, Yevgeniy Valeyev
<webmas...@gmail.com> wrote:
> I want to test if router passes params into controller correctly (Such weird
> task).(in unit test)

Hmm, are you talking about the 'resolve' property of the route
definition? If so this probably shouldn't be tested in the unit test
(you would be testing the framework in this case). Inside e2e tests
you also wouldn't test it explicitly, as you would verify effect
through UI.

Could you share some code to illustrate what you mean exactly by
"router passes params into controller"?

Cheers,
Pawel

--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

Yevgeniy Valeyev

unread,
Dec 10, 2012, 8:14:30 AM12/10/12
to ang...@googlegroups.com

Something like that :) http://jsfiddle.net/ujeen/2J9su/

понедельник, 10 декабря 2012 г., 14:59:25 UTC+2 пользователь Pawel Kozlowski написал:

Pawel Kozlowski

unread,
Dec 10, 2012, 8:16:16 AM12/10/12
to ang...@googlegroups.com
Hey,

I was after the code you are trying to test...
How the AtomDetailsCtrl looks like?

Cheers,
Pawel

On Mon, Dec 10, 2012 at 2:14 PM, Yevgeniy Valeyev
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
>
>



Yevgeniy Valeyev

unread,
Dec 10, 2012, 8:30:02 AM12/10/12
to ang...@googlegroups.com
It seems simple but I don't know how
http://jsfiddle.net/ujeen/N5ZtL/2/

понедельник, 10 декабря 2012 г., 15:16:16 UTC+2 пользователь Pawel Kozlowski написал:

Pawel Kozlowski

unread,
Dec 10, 2012, 8:36:38 AM12/10/12
to ang...@googlegroups.com
Hey,

The only thing that your controller does atm is this:
$scope.route = $routeParams;

and you could test it (from to of my head):

expect(scope.route).toBeDefined();

The bottom line is that you should be testing only _your_ code and not
the framework internals.

I guess it doesn't address all of your concerns so come back when
you've got more code in your controller.

Cheers,
Pawel


On Mon, Dec 10, 2012 at 2:30 PM, Yevgeniy Valeyev

Peter Bacon Darwin

unread,
Dec 10, 2012, 8:36:46 AM12/10/12
to ang...@googlegroups.com
If you want to "unit" test the controller then you should mock up the $routeParams in your test.
If you want to test that the $routeParams are correct for different urls then you can set the current url using $location and then check what the $routeParams are.
Pete

Yevgeniy Valeyev

unread,
Dec 10, 2012, 8:41:34 AM12/10/12
to ang...@googlegroups.com
great, thanks

понедельник, 10 декабря 2012 г., 15:36:46 UTC+2 пользователь Peter Bacon Darwin написал:

Xi Shen

unread,
Dec 10, 2012, 10:10:38 AM12/10/12
to ang...@googlegroups.com
Directly test the $routeParams is really good idea. :) 

Xi Shen

unread,
Dec 23, 2012, 6:49:13 AM12/23/12
to ang...@googlegroups.com
Hi all,

I did not have time to try out this idea. But it seems it does not work for me :( Here's my code:

describe('ng route', function () {
  var $injector = angular.injector();

  beforeEach(module('blog'));

  it('should route to /blog/admin', inject(function ($route, $routeParams, $location) {
    $location.path('/blog/admin');

    dump($route);
    dump($routeParams);
  }));
});

in the console, the dump for $route is all the routes I defined; but the dump for $routeParams is an empty object.

@Peter, I am not sure if I understand you correctly. Please correct me.


Thanks,
David
Reply all
Reply to author
Forward
0 new messages