Skip to content

Instantly share code, notes, and snippets.

@jennifer-shehane
Created February 2, 2018 21:24
Show Gist options
  • Save jennifer-shehane/79e331afef286c683911625ebc3913e6 to your computer and use it in GitHub Desktop.
Save jennifer-shehane/79e331afef286c683911625ebc3913e6 to your computer and use it in GitHub Desktop.
Auth0 testing
## Tests to make sure we're calling auth0 correctly
context "popup display on login", ->
it "displays github popup", ->
cy.visit("/#/login", {
onLoad: (win) ->
@loginWithPopup = cy.stub(win.Auth0.prototype, "loginWithPopup")
})
cy.contains("Log In with GitHub").click()
.then ->
expect(@loginWithPopup).to.be.called
expect(@loginWithPopup.args[0][0].connection).to.eq("github")
## My login command I use for other tests
token='zovL2N5cHJlc3MuYXV0aDAuY29tLyIsInN1YiI6ImdpdGh1YnwxMjcxMzY0IiwiYXVkIjoiWFRkQ2xTOEE5MURueExabzFUTjZQakRTMGNMWklmaUQiLCJleHAiOjE0NjE4MDQ4MjIsImlhdCI6MTQ2MTc2ODgyMn0.DIOpihizE3S1vf-QKSpbaTkrEm7Yjz8I-ptg0Y5xkFY'
Cypress.Commands.add "login", (opts = {}) ->
opts.log = false
log = Cypress.log({
autoEnd: false
name: 'login'
})
cy.visit("#/access_token=abc123&id_token=#{token}", opts).then ->
log.snapshot().end()
@jennifer-shehane
Copy link
Author

Also note, in my application code I have this

if (window.env === 'test') {
  // store as a global for stubbing in tests
  window.Auth0 = Auth0
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment