1

I'm trying to test out a case when the select changes and I seem to be having problems - Here's what I have

The test -

describe('Unit: MainCtrl', function() {
 // Load the module with MainCtrl
 beforeEach(module('myApp'));

  var ctrl, scope;
  // inject the $controller and $rootScope services
  // in the beforeEach block
 beforeEach(inject(function($controller, $rootScope) {
// Create a new scope that's a child of the $rootScope
scope = $rootScope.$new();
// Create the controller
ctrl = $controller('MainCtrl', {
  $scope: scope
});

 }));

 it('should create $scope.myPass when type of pass is selected and purchasePass is run', 
function() {
  expect(scope.myPass).toBeUndefined();
  select('itemSelected').option(0);
  scope.purchasePass();
  expect(scope.myPass).toEqual(5);
 });
})

And inside the template I have

<select ng-model="itemSelected"  ng-options="item as item.name for item in selectItems"> </select>

And this is giving me back the error -

ReferenceError: Can't find variable: select

Says I don't have variable select, but I am unsure what I am doing wrong to cause this. Would very much appreciate some help. Thanks!

1 Answer 1

2

select('itemSelected').option(0);

where did you get this functions "select" and "option"?

If you want to change value, you can directly change it on the scope:

scope.itemSelected = 1;
scope.$digest(); // if you have $watch, and want to trigger it
Sign up to request clarification or add additional context in comments.

3 Comments

I think the select/option is Protractor syntax for E2E tests, which isn't available in Jasmine unit tests.
No, Protractor does not have select/option methods. It has different methods like element(by.tagName('select')), element(by.css('select option'))
@lamStalker AngularJS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.