Testing a select tag, angular js and jasmine

心不动则不痛 提交于 2019-12-11 14:02:29

问题


I have this select box which filters when I change another select. Trying to write a e2e test.

This is my markup:

<select id="inputPipe" ng-model="selectedPipe" ng-options="p.title_en for p in pipes"></select>

<select id="inputSize" ng-model="selectedSize" ng-options="s.nominalsize for s in sizesFromPipes"></select>

So when I change the first select the second gets filtered.

This is my e2e test

select('selectedPipe').option('Steel');

Then I'm not sure how to continue.

This a pseudo code:

expect(<select>('sizesFromPipes[5].nominalsize').toBe('DN50')

How do I write the last one correct?


回答1:


Maybe it help you:

select('selectedPipe').option('Steel');
expect(input('selectedPipe').val()).toBe('0'); // key

select('selectedSize').option('DN50');
expect(input('selectedPipe').val()).toBe('1'); // key

I have in my app something like this:

HTML:

<select ng-model="filter.country" ng-options="c.name for c in countries"></select>
<select ng-model="filter.region" ng-options="r.name for r in filter.country.regions"></select>

JavaScript:

it('should filter on country and region select choose', function() {
  select('filter.country').option('Germany');
  // 0 because this is key of selected option
  expect(input('filter.country').val()).toBe('0');

  select('filter.region').option('Hesse');
  // 1 because this is key of selected option
  expect(input('filter.region').val()).toBe('1'); 
});


来源:https://stackoverflow.com/questions/20128018/testing-a-select-tag-angular-js-and-jasmine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!