mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
parent
15b9b9b19d
commit
ff5acb12cf
@ -361,6 +361,6 @@ export function hasChanged(x: unknown, y: unknown): boolean {
|
||||
if (x === y) {
|
||||
return x === 0 && 1 / x !== 1 / (y as number)
|
||||
} else {
|
||||
return x === x && y === y
|
||||
return x === x || y === y
|
||||
}
|
||||
}
|
||||
|
@ -278,4 +278,29 @@ describe('reactivity/reactive', () => {
|
||||
const observed = reactive(original)
|
||||
expect(isReactive(observed)).toBe(false)
|
||||
})
|
||||
|
||||
// #12595
|
||||
test(`should not trigger if value didn't change`, () => {
|
||||
const state = reactive({
|
||||
foo: 1
|
||||
})
|
||||
const spy = vi.fn()
|
||||
effect(() => {
|
||||
state.foo
|
||||
spy()
|
||||
})
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
|
||||
state.foo = 1
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
|
||||
state.foo = NaN
|
||||
expect(spy).toHaveBeenCalledTimes(2)
|
||||
|
||||
state.foo = NaN
|
||||
expect(spy).toHaveBeenCalledTimes(2)
|
||||
|
||||
state.foo = 2
|
||||
expect(spy).toHaveBeenCalledTimes(3)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user