Skip to content

Instantly share code, notes, and snippets.

@innerdaze
Created April 20, 2018 09:47
Show Gist options
  • Save innerdaze/2fe0c6a23ed4aee0f94a0302f9de7e6c to your computer and use it in GitHub Desktop.
Save innerdaze/2fe0c6a23ed4aee0f94a0302f9de7e6c to your computer and use it in GitHub Desktop.
Example Cypress test
describe('The Initialization Form', () => {
beforeEach(() => {
cy.fixture('config.json').as('config')
indexedDB.deleteDatabase('localforage')
cy.server()
cy.route({
method: 'POST',
url: '/',
response: []
})
cy.visit('/', {
onBeforeLoad: win => {
cy.spy(win, 'fetch').as('fetchSpy')
}
})
})
it('successfully loads', () => {
cy.url().should('include', '/initialize')
})
const testCall = (fetchConfig, expectedServiceName) => {
const data = JSON.parse(fetchConfig.body)
expect(data.method).to.eq(expectedServiceName)
}
context('success', () => {
it('synchronizes the remote data', function () {
cy.get('input[name=apiRoot]:first').type(this.config.apiRoot)
cy.get('input[name=storeId]').type(`${this.config.storeId}{enter}`)
cy
.get('@fetchSpy')
.should(spy => {
expect(spy).to.have.callCount(6)
testCall(spy.args[0][1], 'GeneralService.GetTimeStamp')
testCall(spy.args[1][1], 'SystemLoginService.Login')
testCall(spy.args[2][1], 'HandheldService.GetProducts')
testCall(spy.args[3][1], 'HandheldService.GetCategoryTable')
testCall(spy.args[4][1], 'HandheldService.GetCategoryLines')
testCall(spy.args[5][1], 'HandheldService.GetBarcodes')
})
cy.url().should('include', '/login')
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment