Files
baserow/web-frontend/test/unit/database/mixins/gridField.spec.js
alamin-br 71e30fc7ee fix: don't throw when a grid cell or context is gone before it's cleaned up (#6957)
A cell unmounted in the same render it was mounted in has no cell ref yet, and a
context can be hidden after an awaited request outlived it (Sentry FE-BX, FP, FN).
2026-12-01 18:01:30 +01:00

48 lines
1.4 KiB
JavaScript

import { describe, expect, test, vi } from 'vitest'
import { h, nextTick } from 'vue'
import { mount } from '@vue/test-utils'
import gridField from '@baserow/modules/database/mixins/gridField'
import gridFieldInput from '@baserow/modules/database/mixins/gridFieldInput'
const Cell = {
mixins: [gridField, gridFieldInput],
emits: ['created'],
created() {
this.$emit('created')
},
render() {
return h('div', { ref: 'cell' })
},
}
describe('gridField', () => {
test('a selected cell unmounted in the render it was mounted in does not throw', async () => {
// The parent hides the cell again while it is being created, so Vue unmounts
// it in the same flush, before its `cell` ref is set and `mounted` runs.
const Parent = {
data: () => ({ show: false }),
render() {
return this.show
? h(Cell, {
workspaceId: 1,
field: { id: 1, type: 'text' },
value: '',
selected: true,
readOnly: false,
storePrefix: '',
onCreated: () => (this.show = false),
})
: h('div')
},
}
const errorHandler = vi.fn()
const wrapper = mount(Parent, { global: { config: { errorHandler } } })
wrapper.vm.show = true
await nextTick()
expect(wrapper.findComponent(Cell).exists()).toBe(false)
expect(errorHandler).not.toHaveBeenCalled()
})
})