UNPKG

@hero-design/snowflake-guard

Version:

A hero-design bot detecting snowflake usage

55 lines (54 loc) 2.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const reportStyledComponents_1 = __importDefault(require("../reportStyledComponents")); const testUtils_1 = require("../testUtils"); const componentList = { Button: 'Button', Alert: 'Alert', }; const styledAliasName = 'styled'; describe('reportStyledComponents', () => { it('should detect styled components with default component', () => { const source = ` const StyledCard = styled(Button)\` padding: 10px; \`; `; const ast = (0, testUtils_1.parseTypeScript)(source); const locs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName); expect(locs).toEqual([2]); }); it('should detect styled components with compound component', () => { const source = ` const StyledCardIcon = styled(Button.Icon)\` padding: 10px; \`; `; const ast = (0, testUtils_1.parseTypeScript)(source); const locs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName); expect(locs).toEqual([2]); }); it('should detect styled components with spread operator', () => { const source = ` const { Icon } = Button; const StyledIcon = styled(Icon)\` color: red; \`; <StyledIcon />; `; const ast = (0, testUtils_1.parseTypeScript)(source); const locs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName); expect(locs).toEqual([3]); }); it('should not detect non-styled components', () => { const source = ` const NotStyled = Button; `; const ast = (0, testUtils_1.parseTypeScript)(source); const locs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName); expect(locs).toEqual([]); }); });