Sharing Variables in Nested Describes #5741
-
Has anyone found a good way to nest describe blocks in a given, when, then pattern with the ability to share values across describe blocks? I have had no issue doing this in jest. I am now getting this error
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Since vi.mock('services/authentication/authentication', () => ({
validateToken: () => Promise.resolve(mockJwtPayload), /// <--- `mockJwtPayload` is undefined
fetchToken: () => Promise.resolve(mockToken),
}));
describe('urqlAuth', () => {
describe('Given on page load that a user is authenticated', () => {
const mockJwtPayload = { sub: 'userUuid', exp: 1715049540 }; // <-- `mockJwtPayload` is still here I suppose you have some reason you want to define |
Beta Was this translation helpful? Give feedback.
-
Jest hoists Hoisting is required because mocks should be registered before the files are imported, not after. You can use You can also use See more in docs: https://vitest.dev/api/vi.html#vi-mock |
Beta Was this translation helpful? Give feedback.
-
Thanks @sheremet-va and @hi-ogawa for your answers. I think what I needed to wrap my head around was the spying was not just for looking an incoming values or if a function was called, but also for mocking values. I know this is not a great set of tests. I just was playing with how can I get different mocked values back from
|
Beta Was this translation helpful? Give feedback.
Thanks @sheremet-va and @hi-ogawa for your answers. I think what I needed to wrap my head around was the spying was not just for looking an incoming values or if a function was called, but also for mocking values.
I know this is not a great set of tests. I just was playing with how can I get different mocked values back from