2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-05-15 11:59:37 +03:00
Files
bbob/packages/bbob-preset/test/index.test.ts
T
Nikolay Kost 270f5645f8 fix(#206): TagNode.create now with null content argument by default (#233)
* fix: TagNode.create with null content by default

* Create five-meals-sing.md

* fix: tests

* fix(preset): types inference

* fix: preset types

* fix: preset types

* fix: lock file, parser and utils

* refactor: move types to separate package

* fix(preset): add @bbob/core to dev deps

* fix(preset): lock file

* test(preset-vue): create tags

* test(preset-vue): tests

* chore(nx): fix nx cover deps

* chore: changesets
2024-06-24 01:32:15 +03:00

63 lines
1.9 KiB
TypeScript

import { createPreset, PresetTagsDefinition } from '../src';
import { BBobCoreOptions, createTree } from '@bbob/core'
describe('@bbob/preset', () => {
const presetFactory = <Tags extends PresetTagsDefinition = PresetTagsDefinition>(defTags: Tags) => {
const processor = jest.fn((tags, tree, core, options) => tags)
const preset = createPreset<Tags>(defTags, processor)
return {
preset,
processor,
core: {} as BBobCoreOptions
}
}
test('create', () => {
const defTags = { test: () => ({ tag: 'test' }) }
const options = { foo: 'bar' }
const tree = createTree([], {})
const { preset, processor } = presetFactory(defTags);
expect(preset.extend)
.toBeDefined();
expect(preset)
.toBeInstanceOf(Function);
expect(preset(options)(tree)).toEqual(defTags);
expect(processor.mock.calls.length).toBe(1);
});
test('extend', () => {
const defTags = { foo: () => ({ tag: 'foo'}) }
const extendedTags = { bar: () =>({tag: 'bar'}) }
const options = { foo: 'bar' }
const tree = createTree([], {})
const { preset, processor, core } = presetFactory(defTags);
const newPreset = preset.extend(tags => ({ ...tags, ...extendedTags }));
expect(preset)
.toBeInstanceOf(Function);
expect(newPreset)
.toBeInstanceOf(Function);
const newPresetRes = newPreset(options)
expect(newPresetRes(tree)).toEqual({...defTags, ...extendedTags});
expect(processor.mock.calls.length).toBe(1);
});
test('pass options', () => {
const { preset } = presetFactory({ test: () => ({tag: 'test'}) });
const newPreset = preset.extend((tags, options) => ({ bar: () => ({tag: 'bar'}) }));
const instance = preset({ foo: 'bar' });
const instance2 = newPreset({ some: 'some' });
expect(instance.options)
.toEqual({ foo: 'bar' });
expect(instance2.options)
.toEqual({ some: 'some' })
});
});