UNPKG

@portabletext/schema

Version:
47 lines (41 loc) 1.35 kB
import {describe, expect, test, vi} from 'vitest' import {compileSchema} from './compile-schema' describe(compileSchema.name, () => { describe('block fields', () => { test('reserved fields are ignored and warned about', () => { const consoleWarnSpy = vi .spyOn(console, 'warn') .mockImplementation(() => {}) expect( compileSchema({block: {fields: [{name: '_type', type: 'string'}]}}), ).toEqual({ block: {name: 'block'}, span: {name: 'span'}, styles: [{value: 'normal', name: 'normal', title: 'Normal'}], lists: [], decorators: [], annotations: [], blockObjects: [], inlineObjects: [], }) expect(consoleWarnSpy).toHaveBeenCalledWith( '"_type" is a reserved field name on Portable Text blocks', ) consoleWarnSpy.mockRestore() }) test('custom fields are included', () => { expect( compileSchema({block: {fields: [{name: 'foo', type: 'string'}]}}), ).toEqual({ block: {name: 'block', fields: [{name: 'foo', type: 'string'}]}, span: {name: 'span'}, styles: [{value: 'normal', name: 'normal', title: 'Normal'}], lists: [], decorators: [], annotations: [], blockObjects: [], inlineObjects: [], }) }) }) })