Skip to content

Conversation

@hdJerry
Copy link

@hdJerry hdJerry commented Oct 23, 2025

I noticed a few things which I am not sure if it was delibrate

  • I updated the todo app in the examples to use script setup
  • updated the test to use describe and it just like all the tests on the project
  • updated the comment on the test in examples
  • added some types

I noticed I couldn't run the test until I included the path to where the todo app test is, like so:

include: ['tests/**/*.spec.ts', 'examples/**/*.spec.js'],

@netlify
Copy link

netlify bot commented Oct 23, 2025

Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit 7659c09
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/68fbd649f9f2cc0008d4232b
😎 Deploy Preview https://deploy-preview-2727--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Member

@cexbrayat cexbrayat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!


expect(wrapper.findAll('[data-test="todo"]')).toHaveLength(2)
})
it('should not creates duplicate todo', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creates -> create
duplicate -> duplicated

id: number;
text: string;
completed: boolean;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use an interface named Todo here:

interface Todo {
  id: number;

v-for="todo in todos"
:key="todo.id"
data-test="todo"
:class="getClass(todo.completed)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use: `:class="{ complete: todo.completed }" instead

Copy link
Author

@hdJerry hdJerry Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check it out. I just refactored what was there @cexbrayat
Thank you

const createTodo = () =>{
const listLength = todos.value.length;
const lastItem = todos.value[listLength - 1];// get last todo item
const todoExist = todos.value.find(res => res.text.toLowerCase() === newTodo.value.toLowerCase());//check is todo already exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the example as simple as it was and remove this

Copy link
Author

@hdJerry hdJerry Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the other is simple, but If we kept it the same, it wouldn’t act like a real TODO list — we’d end up with duplicate texts and IDs. So I added a small tweak to make the tests more realistic.
@cexbrayat

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's important to be realistic, a simple version is enough 👍

@@ -1,32 +1,49 @@
/**
* This is the example app used in the documentation.
* If you want to run it, you will need to build the final bundle with
* yarn build. Then you can run this with `yarn test examples`
* pnpm build. Then you can run this with `pnpm test examples`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test file should be in TypeScript (and all references in docs should be updated accordingly)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and all references in docs should be updated accordingly

Can you explain what you mean? @cexbrayat

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case this file is referenced somewhere in the docs, but maybe it isn't 👍

expect(wrapper.find('[data-test="todo"]').text()).toBe('Learn Vue.js 3')
})
expect(wrapper.find('[data-test="todo"]').text()).toBe('Learn Vue.js 3')
expect(wrapper.findAll('[data-test="todo"]')).toHaveLength(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in real life, I would check the number of todos before checking the text, so I would switch the order of these 2 lines


await wrapper.find('[data-test="todo-checkbox"]').setChecked()
await wrapper.find('[data-test="todo-checkbox"]').setChecked()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also check that the class is not on the element before this line

const todoExist = todos.value.find(res => res.text.toLowerCase() === newTodo.value.toLowerCase());//check is todo already exists
if(newTodo.value && !todoExist) {
const id = lastItem.id + 1;//increment the last item id by 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should a space before the comment, but it's weird that prettier did not catch it

@hdJerry hdJerry requested a review from cexbrayat October 24, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants