You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating new test files that use snapshot testing:
103
+
104
+
1. Import the normalization utility
105
+
2. Apply it to your template before comparing with snapshots
106
+
3. Update your snapshots with the `-u` flag
107
+
108
+
## Extending the Utility
109
+
110
+
If you encounter other environment-specific values that need normalization, you can extend the utility at `typescript/test-utils/normalize-template.ts`.
111
+
112
+
Example of adding a new normalization rule:
113
+
114
+
```typescript
115
+
// Inside the normalizeValues function
116
+
if (key==='NewPropertyToNormalize'&&typeofobj[key] ==='string'&&/pattern-to-match/.test(obj[key])) {
117
+
obj[key] ='NORMALIZED_VALUE';
118
+
}
119
+
```
120
+
121
+
## Troubleshooting
122
+
123
+
If you're still seeing snapshot test failures:
124
+
125
+
1.**Check for new patterns**: There might be new types of asset hashes or environment-specific values that need normalization
126
+
2.**Verify imports**: Make sure you're importing and using the utility correctly
127
+
3.**Check snapshot updates**: Ensure you've updated your snapshots after adding normalization
128
+
4.**TypeScript configuration**: If you're getting compilation errors about files outside your project directory, check your tsconfig.json settings
129
+
130
+
## Best Practices
131
+
132
+
1.**Always normalize before snapshot comparison**: This ensures consistent results
133
+
2.**Update snapshots deliberately**: Only use the `-u` flag when you expect changes
134
+
3.**Review snapshot diffs**: When updating snapshots, review the changes to ensure they're expected
135
+
4.**Keep the utility updated**: As new patterns emerge, add them to the normalization utility
0 commit comments