AngularJS测试$ routeParams

时间:2014-11-07 00:04:18

标签: angularjs

我需要测试我的应用程序使用不同的$ routeParams做什么。但我无法弄清楚如何更改每个测试的参数,因为它们是在beforeEach函数中设置的。

beforeEach(inject(function($controller, $rootScope) {
  scope = $rootScope.$new();

    $controller('MyController', {
    $scope: scope,
    $routeParams: routeParams,
  });
}));

我想写这样的东西:

it('resets the results', function() {
  scope.foo = [1];
  scope.resetFoo();
  expect(scope.foo.length).toEqual(0);
});

it('does not resets the results when the params are something...', function() {
  $routeParams = {}; // change this but this doesn't work...
  scope.foo = [1];
  scope.resetFoo(); // put a condition in here to get this to pass.
  expect(scope.foo.length).toEqual(1);
});

如何测试$ routeParams和控制器行为?我在这里采取了错误的做法吗?

0 个答案:

没有答案