Files
tiptap/tests/cypress/integration/core/extensionOptions.spec.ts
Philipp Kühn 9afadeb7fe feat!: Replace defaultOptions with addOptions (#2088)
* add new addOptions option

* replace defaultOptions with addOptions for all extensions

* replace defaultOptions with addOptions for all demos

* replace defaultOptions with addOptions in docs

* refactoring

* refactoring

* drop object support for addOptions

* fix optional options

* fix tests
2021-10-26 18:31:13 +02:00

320 lines
5.5 KiB
TypeScript

/// <reference types="cypress" />
import { Extension } from '@tiptap/core/src/Extension'
describe('extension options', () => {
it('should set options (deprecated)', () => {
const extension = Extension.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
expect(extension.options).to.deep.eq({
foo: 1,
bar: 1,
})
})
it('should set options', () => {
const extension = Extension.create({
addOptions() {
return {
foo: 1,
bar: 1,
}
},
})
expect(extension.options).to.deep.eq({
foo: 1,
bar: 1,
})
})
it('should pass through (deprecated)', () => {
const extension = Extension
.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
.extend()
.configure()
expect(extension.options).to.deep.eq({
foo: 1,
bar: 1,
})
})
it('should pass through', () => {
const extension = Extension
.create({
addOptions() {
return {
foo: 1,
bar: 1,
}
},
})
.extend()
.configure()
expect(extension.options).to.deep.eq({
foo: 1,
bar: 1,
})
})
it('should be configurable (deprecated)', () => {
const extension = Extension
.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
.configure({
bar: 2,
})
expect(extension.options).to.deep.eq({
foo: 1,
bar: 2,
})
})
it('should be configurable', () => {
const extension = Extension
.create({
addOptions() {
return {
foo: 1,
bar: 1,
}
},
})
.configure({
bar: 2,
})
expect(extension.options).to.deep.eq({
foo: 1,
bar: 2,
})
})
it('should be extendable (deprecated)', () => {
const extension = Extension.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
const newExtension = extension.extend({
defaultOptions: {
...extension.options,
baz: 1,
},
})
expect(newExtension.options).to.deep.eq({
foo: 1,
bar: 1,
baz: 1,
})
})
it('should be extendable', () => {
const extension = Extension.create({
addOptions() {
return {
foo: 1,
bar: 1,
}
},
})
const newExtension = extension.extend({
addOptions() {
return {
...this.parent?.(),
baz: 1,
}
},
})
expect(newExtension.options).to.deep.eq({
foo: 1,
bar: 1,
baz: 1,
})
})
it('should be overwritable (deprecated)', () => {
const extension = Extension
.create({
defaultOptions: {
foo: 1,
bar: 1,
},
})
.extend({
defaultOptions: {
baz: 1,
},
})
expect(extension.options).to.deep.eq({
baz: 1,
})
})
it('should be overwritable', () => {
const extension = Extension
.create({
addOptions() {
return {
foo: 1,
bar: 1,
}
},
})
.extend({
addOptions() {
return {
baz: 1,
}
},
})
expect(extension.options).to.deep.eq({
baz: 1,
})
})
it('should configure nested objects (deprecated)', () => {
const extension = Extension
.create<{
foo: number[],
HTMLAttributes: Record<string, any>,
}>({
defaultOptions: {
foo: [1, 2, 3],
HTMLAttributes: {
class: 'foo',
},
},
})
.configure({
foo: [1],
HTMLAttributes: {
id: 'bar',
},
})
expect(extension.options).to.deep.eq({
foo: [1],
HTMLAttributes: {
class: 'foo',
id: 'bar',
},
})
})
it('should configure nested objects', () => {
const extension = Extension
.create<{
foo: number[],
HTMLAttributes: Record<string, any>,
}>({
addOptions() {
return {
foo: [1, 2, 3],
HTMLAttributes: {
class: 'foo',
},
}
},
})
.configure({
foo: [1],
HTMLAttributes: {
id: 'bar',
},
})
expect(extension.options).to.deep.eq({
foo: [1],
HTMLAttributes: {
class: 'foo',
id: 'bar',
},
})
})
it('should create its own instance on configure (deprecated)', () => {
const extension = Extension
.create({
defaultOptions: {
foo: 1,
bar: 2,
},
})
const extension1 = extension.configure({
foo: 2,
bar: 4,
})
const extension2 = extension.configure({
foo: 3,
})
expect(extension1.options).to.deep.eq({
foo: 2,
bar: 4,
})
expect(extension2.options).to.deep.eq({
foo: 3,
bar: 2,
})
})
it('should create its own instance on configure', () => {
const extension = Extension
.create({
addOptions() {
return {
foo: 1,
bar: 2,
}
},
})
const extension1 = extension.configure({
foo: 2,
bar: 4,
})
const extension2 = extension.configure({
foo: 3,
})
expect(extension1.options).to.deep.eq({
foo: 2,
bar: 4,
})
expect(extension2.options).to.deep.eq({
foo: 3,
bar: 2,
})
})
})