0
我使用ng-pattern進行驗證,使用ng-show顯示錯誤消息。這在瀏覽器上工作正常,但我如何在e2e中編碼以測試錯誤消息是否顯示?Angular e2e測試ng-show
這裏是我的HTML:
<input type="text" ng-model="test.pname" name="pname" ng-maxlength="30" ng-pattern="/^[a-zA-Z0-9 ]*$/"/>
<span class="custom-error" id="pnameValidate" ng-show="addProviderForm.pname.$error.pattern">
PName can be Alpha-Numeric up to 30 characters – spaces allowed, but no special characters</span>
這裏是我的E2E腳本:
input('test.pname').enter('cakes`');
expect(element('#pnameValidate:visible').text()).toMatch(/up to 30 characters/);
input('test.pname').enter('cakes are good');
expect(element('#pnameValidate:visible').text()).toBe('');
下面是測試運行的結果:
expected "" but was "\n PName can be Alpha-Numeric up to 30 characters – spaces allowed, but no special characters"
似乎在測試運行無論我在e2e中指定什麼,#pnameValidate總是顯示。