0
# Test Structure
1
2
Hierarchical test organization system supporting both traditional and BDD naming conventions with nested module support for complex test suites.
3
4
## Capabilities
5
6
### Module Organization
7
8
Groups related tests together with optional nesting for complex test organization.
9
10
```scss { .api }
11
/**
12
* Creates a test module for grouping related tests and sub-modules
13
* @param $name - Name of the test module
14
* @content Include tests and sub-modules within this module
15
*/
16
@mixin test-module($name);
17
18
/**
19
* BDD-style alias for test-module
20
* @param $name - Name of the module/feature being described
21
* @content Include tests and sub-modules within this describe block
22
*/
23
@mixin describe($name);
24
```
25
26
**Usage Examples:**
27
28
```scss
29
@use 'pkg:sass-true' as *;
30
31
// Traditional syntax
32
@include test-module('Math Utilities') {
33
@include test-module('Addition Functions') {
34
@include test('adds positive numbers') {
35
@include assert-equal(add(2, 3), 5);
36
}
37
38
@include test('adds negative numbers') {
39
@include assert-equal(add(-2, -3), -5);
40
}
41
}
42
43
@include test-module('Subtraction Functions') {
44
@include test('subtracts correctly') {
45
@include assert-equal(subtract(5, 3), 2);
46
}
47
}
48
}
49
50
// BDD syntax (equivalent)
51
@include describe('Math Utilities') {
52
@include describe('Addition Functions') {
53
@include it('adds positive numbers') {
54
@include assert-equal(add(2, 3), 5);
55
}
56
}
57
}
58
```
59
60
### Test Definition
61
62
Defines individual test cases containing one or more assertions.
63
64
```scss { .api }
65
/**
66
* Creates a test case containing related assertions
67
* @param $name - Description of what is being tested
68
* @content Include assertions that validate the behavior being tested
69
*/
70
@mixin test($name);
71
72
/**
73
* BDD-style alias for test
74
* @param $name - Description of the behavior being tested
75
* @content Include assertions that validate the expected behavior
76
*/
77
@mixin it($name);
78
```
79
80
**Usage Examples:**
81
82
```scss
83
@use 'pkg:sass-true' as *;
84
85
@include test-module('String Functions') {
86
@include test('capitalizes first letter correctly') {
87
@include assert-equal(capitalize('hello'), 'Hello');
88
@include assert-equal(capitalize('WORLD'), 'WORLD');
89
@include assert-equal(capitalize(''), '');
90
}
91
92
@include test('handles edge cases') {
93
@include assert-equal(capitalize(null), null);
94
@include assert-equal(capitalize(123), 123);
95
}
96
}
97
98
// BDD equivalent
99
@include describe('String Functions') {
100
@include it('capitalizes first letter correctly') {
101
@include assert-equal(capitalize('hello'), 'Hello');
102
}
103
104
@include it('handles edge cases') {
105
@include assert-equal(capitalize(null), null);
106
}
107
}
108
```
109
110
### Nested Organization
111
112
Modules can be nested to any depth for organizing complex test suites.
113
114
```scss
115
@use 'pkg:sass-true' as *;
116
117
@include describe('Component Library') {
118
@include describe('Layout Components') {
119
@include describe('Grid System') {
120
@include describe('Grid Container') {
121
@include it('sets correct container width') {
122
@include assert-equal(grid-container-width(), 1200px);
123
}
124
}
125
126
@include describe('Grid Columns') {
127
@include it('calculates column width correctly') {
128
@include assert-equal(grid-column-width(12, 1200px), 100px);
129
}
130
}
131
}
132
}
133
134
@include describe('Typography Components') {
135
@include it('generates font sizes correctly') {
136
@include assert-equal(font-size('large'), 1.25rem);
137
}
138
}
139
}
140
```
141
142
## Best Practices
143
144
### Naming Conventions
145
146
- **Module names**: Use descriptive names that group related functionality (e.g., "Math Functions", "Color Utilities")
147
- **Test names**: Use action-oriented descriptions (e.g., "adds two numbers", "returns correct color value")
148
- **BDD style**: Use natural language descriptions (e.g., "should add two numbers correctly")
149
150
### Organization Patterns
151
152
```scss
153
// Group by function/feature
154
@include describe('Button Mixin') {
155
@include it('generates base button styles') { /* ... */ }
156
@include it('handles size variants') { /* ... */ }
157
@include it('handles color themes') { /* ... */ }
158
}
159
160
// Group by use case
161
@include describe('Responsive Typography') {
162
@include describe('Mobile Breakpoint') {
163
@include it('uses smaller font sizes') { /* ... */ }
164
}
165
@include describe('Desktop Breakpoint') {
166
@include it('uses larger font sizes') { /* ... */ }
167
}
168
}
169
```
170
171
### Mixed Testing Approaches
172
173
You can mix value assertions and CSS output testing within the same test structure:
174
175
```scss
176
@include describe('Button Mixin') {
177
@include it('calculates padding correctly') {
178
// Test function return value
179
@include assert-equal(button-padding('small'), 0.5rem 1rem);
180
}
181
182
@include it('generates correct CSS output') {
183
// Test CSS output
184
@include assert {
185
@include output {
186
@include button('primary', 'large');
187
}
188
@include expect {
189
padding: 1rem 2rem;
190
background-color: #007bff;
191
border: none;
192
border-radius: 0.25rem;
193
}
194
}
195
}
196
}
197
```