mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-19 13:47:51 +08:00
d3aeac4afa
* Fix TipTap getting loaded as CommonJS when the intent is to use the ES Module version. * `package.json` change also makes explicit exports required * Update `core` utilities exports to include all utilities * Update tests to use exported utilities
134 lines
2.5 KiB
TypeScript
134 lines
2.5 KiB
TypeScript
/// <reference types="cypress" />
|
|
|
|
import { Extension, getExtensionField } from '@tiptap/core'
|
|
|
|
describe('extend extensions', () => {
|
|
it('should define a config', () => {
|
|
const extension = Extension.create({
|
|
addAttributes() {
|
|
return {
|
|
foo: {},
|
|
}
|
|
},
|
|
})
|
|
|
|
const attributes = getExtensionField(extension, 'addAttributes')()
|
|
|
|
expect(attributes).to.deep.eq({
|
|
foo: {},
|
|
})
|
|
})
|
|
|
|
it('should overwrite a config', () => {
|
|
const extension = Extension
|
|
.create({
|
|
addAttributes() {
|
|
return {
|
|
foo: {},
|
|
}
|
|
},
|
|
})
|
|
.extend({
|
|
addAttributes() {
|
|
return {
|
|
bar: {},
|
|
}
|
|
},
|
|
})
|
|
|
|
const attributes = getExtensionField(extension, 'addAttributes')()
|
|
|
|
expect(attributes).to.deep.eq({
|
|
bar: {},
|
|
})
|
|
})
|
|
|
|
it('should merge configs', () => {
|
|
const extension = Extension
|
|
.create({
|
|
addAttributes() {
|
|
return {
|
|
foo: {},
|
|
}
|
|
},
|
|
})
|
|
.extend({
|
|
addAttributes() {
|
|
return {
|
|
...this.parent?.(),
|
|
bar: {},
|
|
}
|
|
},
|
|
})
|
|
|
|
const attributes = getExtensionField(extension, 'addAttributes')()
|
|
|
|
expect(attributes).to.deep.eq({
|
|
foo: {},
|
|
bar: {},
|
|
})
|
|
})
|
|
|
|
it('should merge configs multiple times', () => {
|
|
const extension = Extension
|
|
.create({
|
|
addAttributes() {
|
|
return {
|
|
foo: {},
|
|
}
|
|
},
|
|
})
|
|
.extend({
|
|
addAttributes() {
|
|
return {
|
|
...this.parent?.(),
|
|
bar: {},
|
|
}
|
|
},
|
|
})
|
|
.extend({
|
|
addAttributes() {
|
|
return {
|
|
...this.parent?.(),
|
|
baz: {},
|
|
}
|
|
},
|
|
})
|
|
|
|
const attributes = getExtensionField(extension, 'addAttributes')()
|
|
|
|
expect(attributes).to.deep.eq({
|
|
foo: {},
|
|
bar: {},
|
|
baz: {},
|
|
})
|
|
})
|
|
|
|
it('should merge configs without direct parent configuration', () => {
|
|
const extension = Extension
|
|
.create({
|
|
addAttributes() {
|
|
return {
|
|
foo: {},
|
|
}
|
|
},
|
|
})
|
|
.extend()
|
|
.extend({
|
|
addAttributes() {
|
|
return {
|
|
...this.parent?.(),
|
|
bar: {},
|
|
}
|
|
},
|
|
})
|
|
|
|
const attributes = getExtensionField(extension, 'addAttributes')()
|
|
|
|
expect(attributes).to.deep.eq({
|
|
foo: {},
|
|
bar: {},
|
|
})
|
|
})
|
|
})
|