handsome-kilobyte-99728
06/03/2021, 10:02 PMbulky-sundown-74498
06/03/2021, 10:05 PMbulky-sundown-74498
06/03/2021, 10:06 PMbulky-sundown-74498
06/03/2021, 10:07 PMbulky-sundown-74498
06/03/2021, 10:07 PMbulky-sundown-74498
06/03/2021, 10:17 PMbulky-sundown-74498
06/03/2021, 10:19 PMhandsome-kilobyte-99728
06/04/2021, 12:05 AMhallowed-orange-38556
06/04/2021, 4:08 AMflat-electrician-52949
06/04/2021, 8:43 AMcy.tick()
working as I expect. Got this case:
ts
const [minutesLeft, minutesLeftSet] = React.useState<number>(10)
React.useEffect(() => {
let timer
if (minutesLeft > 0) {
timer = setTimeout(() => {
console.log(new Date())
minutesLeftSet((minutesLeft) => minutesLeft - 1)
}, 1000 /*ms*/ * 60 /*sec*/ * 1 /*min*/)
}
return () => {
if (timer) clearTimeout(timer)
}
}, [minutesLeft])
(this is finial version - it will do it from a date but this is fine for now)
ts
...
/ Time left
cy.contains('10 min', { matchCase: false }).should('be.visible')
cy.tick(1000 /*ms*/ * 60 /*sec*/ * 1 /*min*/ + 300 /*ms*/)
cy.contains('9 min', { matchCase: false }).should('be.visible')
cy.tick(1000 /*ms*/ * 60 /*sec*/ * 1 /*min*/ + 300 /*ms*/)
cy.contains('8 min', { matchCase: false }).should('be.visible')
flat-electrician-52949
06/04/2021, 8:45 AMflat-electrician-52949
06/04/2021, 8:46 AMicy-rainbow-39970
06/04/2021, 8:46 AMflat-electrician-52949
06/04/2021, 8:46 AMflat-electrician-52949
06/04/2021, 8:47 AMts
it.only('shows a ticket order and an estimate on when it is ready', () => {
cy.stub(nextRouterMock, 'useRouter').callsFake((): Partial<TRouter> => {
return { query: { ticketNumber: '7' } }
})
const now = new Date()
cy.clock(now)
mount(
<>
<ResizeWrapper>
<CartProvider>
<PaymentSucceededMessage />
</CartProvider>
</ResizeWrapper>
</>
)
// Ticket number
cy.findByText('Ditt biljettnummer är').should('be.visible')
cy.findByText('7').should('be.visible')
// Time left
cy.contains('10 min', { matchCase: false }).should('be.visible')
cy.tick(1000 /*ms*/ * 60 /*sec*/ * 1 /*min*/ + 300 /*ms*/)
cy.contains('9 min', { matchCase: false }).should('be.visible')
cy.tick(1000 /*ms*/ * 60 /*sec*/ * 1 /*min*/ + 300 /*ms*/)
cy.contains('8 min', { matchCase: false }).should('be.visible')
cy.contains('Om du inte har angett en annan gång i anteckningen till köket')
})
flat-electrician-52949
06/04/2021, 8:48 AMflat-electrician-52949
06/04/2021, 8:50 AMuser
06/04/2021, 9:52 AMuser
06/04/2021, 9:53 AMbillowy-spoon-30011
06/04/2021, 3:26 PMechoing-piano-69699
06/04/2021, 5:11 PMechoing-piano-69699
06/04/2021, 5:11 PMbillowy-spoon-30011
06/04/2021, 5:11 PMechoing-piano-69699
06/04/2021, 5:12 PMbillowy-spoon-30011
06/04/2021, 5:14 PMechoing-piano-69699
06/04/2021, 5:15 PMwindow.location.href = /*your variable value*/
billowy-spoon-30011
06/04/2021, 5:15 PMechoing-piano-69699
06/04/2021, 5:16 PMcy.spy
and cy.stub
but it doesn't seem to be working the way I expect it to
I have tried instantiating both of these in different places (at beginning of describe
, in beforeEach
, etc.) but haven't gotten it to work
I am definitely calling the methods I'm spying on but something appears to not be connected in how I'm testing this with Cypressechoing-piano-69699
06/04/2021, 5:52 PMtypescript
import segment from 'utils/segment'
export {}
const formDefinition = {}
describe('Analytics', () => {
beforeEach(() => {
cy.intercept('/metric/formio/latency', { statusCode: 200 })
})
describe('page navigation', () => {
beforeEach(() => {
cy.visit('/cypress_tests', {
onBeforeLoad() {
cy.spy(segment, 'init').as('initSpy')
cy.spy(segment, 'track').as('trackSpy')
}
})
cy.loadForm(formDefinition)
})
it('initializes segment', () => {
cy.get('@initSpy').should('be.called')
})
})
})
echoing-piano-69699
06/04/2021, 6:02 PMinit
available as an individual export and changing my import to import * as segment from 'utils/segment'
but got this error Attempted to wrap undefined property init as function
so I don't think that's the correct route to take