Tumulte
Tumulte
NNuxt
Created by Tumulte on 8/30/2024 in #❓・help
How do you spy on mockNuxtImport methods ? (navigateTo())
using vitest I’d like to check that navigateTo has been called. But I can’t find how to setup the spy properly to use "hasBeenCalled"
1 replies
NNuxt
Created by Tumulte on 8/21/2024 in #❓・help
How do you refresh a fetch with a dynamic path (/api/page/[id])
I have a hard time understanding that doc https://nuxt.com/docs/getting-started/data-fetching#computed-url Basically I have a fetch {data, refresh} = useFetch("/api/${dynamicID}") (<- I know it’s suposed to be ) but when I refresh the dynamicID doesn’t change which is normal... but what’s the workaround (note that I can’t use watch because it’s on immediate: false` and I need to refresh it on cue) ?
11 replies
NNuxt
Created by Tumulte on 5/23/2024 in #❓・help
registerEndpoint returning data from a previous registerEnpoint
I have 2 end points for a test...
registerEndpoint('/api/channel/preview', {
method: 'POST',
handler: () => {
return { query: 'query', content: posts };
},
});

registerEndpoint('/api/channel/preview/translator', {
method: 'POST',
handler: () => {
return { prompt: 'new prompt' };
},
});
registerEndpoint('/api/channel/preview', {
method: 'POST',
handler: () => {
return { query: 'query', content: posts };
},
});

registerEndpoint('/api/channel/preview/translator', {
method: 'POST',
handler: () => {
return { prompt: 'new prompt' };
},
});
but when I call the second enpoint, it gives me the data from the first {query:... content:...} however if I swap their position in the test code to match the order they are called... it works I don't understand why the position should matter and the documentation says nothing
3 replies
NNuxt
Created by Tumulte on 5/20/2024 in #❓・help
global registerEndpoint ? (for all tests)
I have middleware that checks and calls a route, and vitest really doesn't like it : every test gives a warning that my route auth/me doesn't exist. Is there a way to mock it for all tests ? I've tried registerEndpoint in setupFiles but no change thanks
1 replies
NNuxt
Created by Tumulte on 5/13/2024 in #❓・help
Is it possible to add descriptions to the nitro experimental openAPI/scalar autogenerated doc ?
The doc auto generation works well, but I can't find how to add descriptions to any given route ? I've read the docs but I don't find anything relevant
nitro: {
experimental: {
openAPI: true,
},
},
nitro: {
experimental: {
openAPI: true,
},
},
1 replies
NNuxt
Created by Tumulte on 5/7/2024 in #❓・help
How to mock useRoute in nuxt ?
I would just like to access route.params.id in vitest BUT, I cannot mock useRoute the way we used to in Nuxt. No matter what, route.params.id is undefined I've tried seting up a route in mountSuspended but to no success. What's the proper way ? Thanks
4 replies
NNuxt
Created by Tumulte on 5/6/2024 in #❓・help
registerEndpoint requires multiple flushPromises
registerEndpoint('/api/channel/1', {
method: 'DELETE',
handler: () => {
return {};
},
});

describe('ChannelMenu', () => {
it('deletes a channel', async () => {
const wrapper = mountWrapper();
const deleteState = useState(DELETE_CHANNEL_ID);
wrapper.vm.deleteChannel();
await flushPromises();
await flushPromises();

expect(deleteState.value).toBe(wrapper.vm.props.channel.idChannel);
});
});
registerEndpoint('/api/channel/1', {
method: 'DELETE',
handler: () => {
return {};
},
});

describe('ChannelMenu', () => {
it('deletes a channel', async () => {
const wrapper = mountWrapper();
const deleteState = useState(DELETE_CHANNEL_ID);
wrapper.vm.deleteChannel();
await flushPromises();
await flushPromises();

expect(deleteState.value).toBe(wrapper.vm.props.channel.idChannel);
});
});
take this code for instance... if I only use 1 flushPromises, the expect won't work. Is it expected ? Is there a workaround ? thanks !
2 replies
NNuxt
Created by Tumulte on 4/30/2024 in #❓・help
registerEndpoint and return status
Apparently setResponseStatus(xxx, event) doesn't work in the handler of registerEndpoint is there a way to set the status to anything other than 200 ? Thanks !
2 replies
NNuxt
Created by Tumulte on 4/19/2024 in #❓・help
Does useState() a default value when the state key already set ?
The doc is unclear on the topic and my tests show contradictory results. Let's say I call a component multiple times with
//component A

const foo = useState('foo', ()=>{user: null})
foo.value.user = 'toto';
//component A

const foo = useState('foo', ()=>{user: null})
foo.value.user = 'toto';
//component B

const foo = useState('foo', ()=>{user: null})
foo.value.user = 'bar';
//component B

const foo = useState('foo', ()=>{user: null})
foo.value.user = 'bar';
will the second useState() be reset to {user: null} then to {user: 'bar'} or is useState smart enough to know it aleady has a value and to not reinstantiate itself ?
23 replies