Currently I am conducting a test on an AngularJS view. The code sample contains some non-standard helpers, but they should not affect the specific functionality being tested.
Below is the view (written in Jade):
#authentication-options
button#sign-up(ui-sref='sign-up') Create an Account
a#sign-in(ui-sref='sign-in') I already have an account.
Here is the spec:
spec 'AuthenticationOptions', ->
beforeEach ->
@view = $view 'authentication-options.html'
describe 'elements', ->
describe 'sign up button', ->
beforeEach ->
@button = findSelector 'button#sign-up', in: @view
it 'exists', ->
expectElement @button
# Initially tried using `triggerHandler`, which did not work as expected.
it 'transitions to sign up when clicked', ->
# @button represents the #sign-up button node wrapped with angular.element.
@button.triggerHandler('click')
get('$rootScope').$digest()
expect(get('$state').current.name).to.eq 'sign-up'
The code functions correctly in the browser but the spec does not change the state as desired. An error message is displayed:
AssertionError: expected 'authentication-options' to equal 'sign-up'
Despite having loaded the entire module, including ui-router
and configured states, the issue persists.
Could there be another event that needs to be triggered or a different method to effectively test the behavior of this button in a unit/integration test rather than a comprehensive E2E test?