Skip to content

Instantly share code, notes, and snippets.

@lorennorman
Last active May 30, 2017 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorennorman/b74d3b5fff46960d6d11eaa1323b3ca0 to your computer and use it in GitHub Desktop.
Save lorennorman/b74d3b5fff46960d6d11eaa1323b3ca0 to your computer and use it in GitHub Desktop.
toying around with alternatives to the `describe`, `context`, `it`, `before`, `after` paradigm
describe "Post Management", ->
# eases visits and URL assertions
pages
posts: '/path/to/posts'
post: '/path/to/posts/:id'
# prepares for querying any elements you'll interact with
elements
submitButton: '.selector-for-submit'
backButton: '.selector-for-back'
# stub or spy XHRs
requests {
getPosts: {
route: 'get /posts'
code: 404
body: {
...
}
}
createPost: 'post /posts' # responds 200 {}
}
# wrap up your interactions
actions {
clickSubmit: ->
cy.get('@submitButton').click()
clickBack: ->
cy.get('@backButton').click()
seeContent: (selector, content) ->
cy.get(selector).contains(content)
}
# visits posts before each test
page '@posts', ->
# easy declarative test flow: given, when, then
verify "Clicking Back returns to Getting Started", ->
clickBack().then(seeContent)
verify -> # prints "Clicking "Submit" shows the message 'Congrats!'"
clickSubmit()
wait('@createPost')
seeContent("Congrats!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment