cool-application-67821
06/21/2021, 9:01 PMbulky-sundown-74498
06/21/2021, 10:56 PMbulky-sundown-74498
06/21/2021, 10:56 PMbulky-sundown-74498
06/21/2021, 10:57 PMcool-application-67821
06/22/2021, 1:50 AMcool-application-67821
06/22/2021, 3:12 AMcool-application-67821
06/22/2021, 3:31 AMuser
06/22/2021, 5:58 PMwide-london-24133
06/23/2021, 7:58 AMwide-london-24133
06/23/2021, 7:59 AMjs
cy.request('POST', 'http://int.oa.com:8080', { bookId: '383' }).then(
(response) => {
// response.body is automatically serialized into JSON
expect(response.body).to.have.property('bookId', '383') // true
}
)
wide-london-24133
06/23/2021, 8:01 AMgray-kilobyte-89541
06/23/2021, 7:44 PMcy...
commands should be in a test. So put your cy.request
inside an it('loads', () => ....)
testwide-london-24133
06/24/2021, 1:45 AMgray-kilobyte-89541
06/24/2021, 1:08 PMquaint-autumn-18886
06/24/2021, 1:25 PMfuture-journalist-95278
06/26/2021, 8:16 AMnext/router
like what is discussed here - https://github.com/vercel/next.js/issues/7479future-journalist-95278
06/26/2021, 8:21 AMuser
06/28/2021, 10:34 AMbulky-sundown-74498
06/28/2021, 2:31 PMcy.intercept()
.
If you are using CT, then one can stub or spy on any module in mocha. Check out this example.
https://github.com/elevatebart/cy-nextjs/blob/main/components/DisplayRoute/DisplayRoute.spec.jsxbulky-sundown-74498
06/28/2021, 2:34 PMfuture-journalist-95278
06/28/2021, 5:08 PMError: TypeError: router.prefetch is not a function
.
This is how I organized my test: js
import { mount } from '@cypress/react'
import * as nextRouter from 'next/router'
import Navbar from '../../component/Navbar'
const LINKS = [
{ text: 'Home', to: '/' },
{ text: 'About', to: '/about' },
{ text: 'Ninja Listing', to: '/ninjas' },
]
describe('<Navbar />', () => {
it.only('displays links', () => {
cy.stub(nextRouter, 'useRouter').callsFake(() => ({ pathname: '/' }))
mount(<Navbar links={LINKS} />)
})
})
bulky-sundown-74498
06/28/2021, 5:22 PMprefetch()
to the pathname ?bulky-sundown-74498
06/28/2021, 5:23 PMcy.stub(nextRouter, 'useRouter').callsFake(() => ({ pathname: '/', prefetch: sinon.stub() }))
bulky-sundown-74498
06/28/2021, 5:24 PMfew-musician-79351
07/02/2021, 5:33 PMwonderful-match-15836
07/02/2021, 6:06 PMgetMatchingCards
returns an empty object right away, because matchingCards
is initialized as empty and the work to populate it all happening asynchronously. So the Object.values(arrMatchingCards)
is called when arrMatchingCards
is still just {}
- which would explain the empty array at that point. Meanwhile everything in the .then
of your cards.each
is happening asynchronously, and since the JS console is showing a live representation of the object, those property assignments appear in the console even though they actually happened to the object after line 41 ran. If this is right, something like console.log(JSON.stringify(cardsMap))
instead of logging the raw object would verify, as it would log an empty object. Same issue would apply where you console log matchingCards
inside your function - it's logging a reference to the live object.few-musician-79351
07/03/2021, 3:12 PMfew-musician-79351
07/05/2021, 7:26 PMfaint-bear-92677
07/05/2021, 8:49 PMuser
07/05/2021, 10:22 PM