Created
November 11, 2021 00:25
-
-
Save niieani/c79b3ca525dbe0ceb0954a318928f2b5 to your computer and use it in GitHub Desktop.
An example Cypress test using Laika's Subscription mocking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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