mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-05 16:42:27 +03:00
cbccbaf896
* chore: initial setup for vue2 packages * feat: basic Vue 2 Component * feat(vue2): add more test cases * test(preset): add more cases to test in preset * test(preset-vue2): add more cases to test tags processing * fix(preset): tag node checking * test(preset-vue): more coverage for vue preset * refactor(vue2): move default export to plugin install func * feat(example-vue2): add vue2 example to examples folder * chore(example-vue2): remove unused npm scripts * chore: add vue 2 example in main README * chore: update package.json descriptions
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
import { createPreset } from '../src/index';
|
|
|
|
describe('@bbob/preset', () => {
|
|
const presetFactory = (defTags) => {
|
|
const processor = jest.fn((tags, tree, core, options) => tags)
|
|
|
|
return [createPreset(defTags, processor), processor];
|
|
}
|
|
|
|
test('create', () => {
|
|
const defTags = { test: true }
|
|
const options = { foo: 'bar' }
|
|
const tree = []
|
|
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: true }
|
|
const extendedTags = { bar: true }
|
|
const options = { foo: 'bar' }
|
|
const tree = []
|
|
const [preset, processor] = presetFactory(defTags);
|
|
const newPreset = preset.extend(tags => ({ ...tags, ...extendedTags }));
|
|
|
|
expect(preset)
|
|
.toBeInstanceOf(Function);
|
|
expect(newPreset)
|
|
.toBeInstanceOf(Function);
|
|
|
|
expect(newPreset(options)(tree)).toEqual({...defTags, ...extendedTags});
|
|
|
|
expect(processor.mock.calls.length).toBe(1);
|
|
});
|
|
test('pass options', () => {
|
|
const [preset, processor] = presetFactory({ test: true });
|
|
const newPreset = preset.extend((tags, options) => ({ bar: true }));
|
|
|
|
const instance = preset({ foo: 'bar' });
|
|
const instance2 = newPreset({ some: true });
|
|
|
|
expect(instance.options)
|
|
.toEqual({ foo: 'bar' });
|
|
expect(instance2.options)
|
|
.toEqual({ some: true });
|
|
});
|
|
});
|