|
| 1 | +// Copyright 2025 Google Inc. Use of this source code is governed by an |
| 2 | +// MIT-style license that can be found in the LICENSE file or at |
| 3 | +// https://opensource.org/licenses/MIT. |
| 4 | + |
| 5 | +import {SelectorExpression} from '../..'; |
| 6 | +import * as utils from '../../../test/utils'; |
| 7 | + |
| 8 | +describe('a selector expression', () => { |
| 9 | + let node: SelectorExpression; |
| 10 | + |
| 11 | + function describeNode( |
| 12 | + description: string, |
| 13 | + create: () => SelectorExpression, |
| 14 | + ): void { |
| 15 | + describe(description, () => { |
| 16 | + beforeEach(() => void (node = create())); |
| 17 | + |
| 18 | + it('has sassType selector', () => |
| 19 | + expect(node.sassType).toBe('selector-expr')); |
| 20 | + }); |
| 21 | + } |
| 22 | + |
| 23 | + describeNode('parsed', () => utils.parseExpression('&')); |
| 24 | + |
| 25 | + describe('constructed manually', () => { |
| 26 | + describeNode('without props', () => new SelectorExpression()); |
| 27 | + |
| 28 | + describeNode('with empty props', () => new SelectorExpression({})); |
| 29 | + }); |
| 30 | + |
| 31 | + it('stringifies', () => |
| 32 | + expect(new SelectorExpression().toString()).toBe('&')); |
| 33 | + |
| 34 | + describe('clone', () => { |
| 35 | + let original: SelectorExpression; |
| 36 | + |
| 37 | + beforeEach(() => void (original = utils.parseExpression('&'))); |
| 38 | + |
| 39 | + describe('with no overrides', () => { |
| 40 | + let clone: SelectorExpression; |
| 41 | + |
| 42 | + beforeEach(() => void (clone = original.clone())); |
| 43 | + |
| 44 | + describe('has the same properties:', () => { |
| 45 | + it('raws', () => expect(clone.raws).toEqual({})); |
| 46 | + |
| 47 | + it('source', () => expect(clone.source).toBe(original.source)); |
| 48 | + }); |
| 49 | + |
| 50 | + it('creates a new self', () => expect(clone).not.toBe(original)); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('overrides', () => { |
| 54 | + describe('raws', () => { |
| 55 | + it('defined', () => |
| 56 | + expect(original.clone({raws: {}}).raws).toEqual({})); |
| 57 | + |
| 58 | + it('undefined', () => |
| 59 | + expect(original.clone({raws: undefined}).raws).toEqual({})); |
| 60 | + }); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('toJSON', () => expect(utils.parseExpression('&')).toMatchSnapshot()); |
| 65 | +}); |
0 commit comments