-
-
Notifications
You must be signed in to change notification settings - Fork 55
feat(switch): added activeValue and inactiveValue #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks, looking at the commit code it was indeed out of my reach (atm). |
Thanks for the PR ❤️ I'm making minor changes:
whoa, You added a test 😍 |
Hi, @jd-solanki, Thank you for taking the time to review my first PR to Open Source Community and provide feedback, Anu is a great project, I really enjoy contributing code to this project. |
Hey @IcetCode After merging, I noticed we have updated |
Sorry, I should mention this change. I changed the prop's type because I found that if an Array or Set type value is passed to This change seems to be a breaking change, and we may need to add more unit test cases to ensure its stability. |
Hi @jd-solanki it('should support setter', () => {
const n = ref(1)
const plusOne = computed({
get: () => n.value + 1,
set: val => {
n.value = val - 1
}
})
expect(plusOne.value).toBe(2)
n.value++
expect(plusOne.value).toBe(3)
plusOne.value = 0
expect(n.value).toBe(-1)
}) |
Just setting it('should have `isChecked` as `true` when `modelValue` is changed to `true`', () => {
const modelValue = ref(false)
const emitMock = vi.fn()
const trueValue = true
const falseValue = false
const { isChecked } = useCheckbox(modelValue, emitMock, trueValue, falseValue)
modelValue.value = true
expect(isChecked.value).toBe(true)
isChecked.value = true // trigger the setter function
expect(emitMock).toBeCalledTimes(1)
expect(emitMock).toHaveBeenCalledWith('update:modelValue', true)
}) |
The reason why the last test case failed is that we did not provide the // before
<input v-model="searchText" />
// after
<input
:value="searchText"
@input="searchText = $event.target.value"
/> We just need to change the mock function like this // before
const emitMock = vitest.fn()
// after
const emitMock = vi.fn((fnName: string, value: string) => {
if (fnName === 'update:modelValue')
modelValue.value = value
}) |
I'm glad to be of help.🥂 |
Hey @jd-solanki , After running the component in tests and the browser, I noticed that the it('color prop changes button color', () => {
const wrapper = shallowMount(ABtn, { props: { color: 'warning' }, slots: { default: 'Click me' } })
const myRegex = /;\s?/g; // match "; " or ";"
const styles = wrapper.attributes('style')?.split(myRegex)
expect(styles).toContain('--a-layer-c: var(--a-warning)')
}) |
oh sorry @IcetCode I totally forgot about this 🙏🏻 Will give it a try for sure! Thanks, Nice to talk to you 😇 |
Hey, @IcetCode Do you have any experience with configuring Playwright inside Vitest? |
Hey, @sandros94 |
Thanks for your input, I want to write more tests to improve robustness however I'm experiencing something is missing from correct test setup like I tried to integrate playwright but it looks like if we use playwright then we have to let go of vitest but at the same time I also found that we can use playwright inside vitest to avoid compromising vitest features like instant feedback ⚡ |
Playwright's component test is still in the experimental stage, maybe we should considering Cypress instead. I think using Cypress or Playwright for component style layer tests, and then extracting the component logic with hooks and testing it with Vitest, is an excellent approach. |
@IcetCode Have you ever tried this? Does it affect the speed of tests, more specifically when I tried playwright in the sample repo I was missing vitest's HMR like speed 😅 ? |
@jd-solanki I noticed that they both use Vite as their bundler, which could be the reason for the slowdown in HMR |
@IcetCode If you know of any project that uses vite and uses Playwright inside vitest for component testing, please let me know. I would like to add the playwright in vitest. Regards. |
I implemented the
active-value
andinactive-value
to ASwitch for #135