UNPKG

@knapsack/app

Version:

Build Design Systems with Knapsack

53 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const file_utils_1 = require("@knapsack/file-utils"); const renderer_utils_1 = require("./renderer-utils"); const format = async (code, codeFormat = 'html') => { try { return (0, file_utils_1.formatCode)({ path: `fake-file.${codeFormat}`, contents: code }); } catch (error) { console.log(code); console.log('^^^^^ Original Code ^^^^^'); throw new Error(error.message); } }; const slotOptionsComputed = { cssClasses: ['foo', 'bar'], styles: { color: 'red', flexDirection: 'row', }, attributes: { 'data-foo': 'bar', }, wrappingElementName: 'div', }; (0, vitest_1.describe)('createSlotOptionsHtmlTags', () => { (0, vitest_1.it)('classAttributeName: className, stylesValueType: string', async () => { const { openTag, closeTag } = (0, renderer_utils_1.createSlotOptionsHtmlTags)({ slotOptionsComputed, classAttributeName: 'className', stylesValueType: 'string', }); (0, vitest_1.expect)(await format(`${openTag}${closeTag}`)).toBe(await format('<div data-foo="bar" className="foo bar" style="color: red; flex-direction: row;"></div>')); }); (0, vitest_1.it)('classAttributeName: class, stylesValueType: string', async () => { const { openTag } = (0, renderer_utils_1.createSlotOptionsHtmlTags)({ slotOptionsComputed, classAttributeName: 'class', stylesValueType: 'string', }); (0, vitest_1.expect)(await format(openTag)).toBe(await format('<div data-foo="bar" class="foo bar" style="color: red; flex-direction: row;">')); }); (0, vitest_1.it)('classAttributeName: className, stylesValueType: object', async () => { const { openTag, closeTag } = (0, renderer_utils_1.createSlotOptionsHtmlTags)({ slotOptionsComputed, classAttributeName: 'className', stylesValueType: 'object', }); (0, vitest_1.expect)(await format(`${openTag}${closeTag}`, 'jsx')).toBe(await format('<div data-foo="bar" className="foo bar" style={{ color: "red", flexDirection: "row" }}></div>', 'jsx')); }); }); //# sourceMappingURL=renderer-utils.test.js.map