Skip to content

Instantly share code, notes, and snippets.

@niieani
Created November 11, 2021 00:25
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 niieani/c79b3ca525dbe0ceb0954a318928f2b5 to your computer and use it in GitHub Desktop.
Save niieani/c79b3ca525dbe0ceb0954a318928f2b5 to your computer and use it in GitHub Desktop.
An example Cypress test using Laika's Subscription mocking
import type {Laika, InterceptApi} from '@zendesk/laika'
describe('My suite', () => {
let laika: Laika
before(() => {
cy.visit('/')
cy.window()
.its('laika')
.then((instance) => {
laika = instance
})
})
it('waits for the subscription, pushes out data and asserts the element updated', () => {
let getActiveUsersInterceptor: InterceptApi
cy.then(() => {
getActiveUsersInterceptor = laika.intercept({ operationName: 'getActiveUsers' })
})
cy.then({ timeout: 5000 }, async () => {
await getActiveUsersInterceptor.waitForActiveSubscription()
getActiveUsersInterceptor.fireSubscriptionUpdate({
result: { data: { count: 10 } },
})
})
cy.get('activeUsers').contains(
'There are 10 users currently active on the website',
)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment