Testing Your Functions
Learn how to test and debug Function Lab configurations.Preview Mode
Function Lab provides a built-in preview mode in the Shopify admin.Accessing Preview
- Navigate to Apps → Function Lab
- Select your function
- Click “Preview” or “Test”
- Enter test cart data
Test Scenarios
Create test scenarios with different:- Customer tags
- Cart contents
- Product variants
- Order totals
- Geographic locations
Common Testing Patterns
Test Customer Segments
Test Cart Conditions
Debugging Strategies
Enable Console Logging
Add console output to track execution:Test Conditions in Isolation
Simplify rules to test one condition at a time:Verify Selector Output
Test selectors separately:Validation Checklist
Before activating a function:- JSON syntax is valid
- All required fields are present
- Predicates are spelled correctly
- Paths reference valid fields
- GIDs are properly formatted
- Discount values are in correct format
- Messages are customer-friendly
- Tested with multiple cart scenarios
- Verified in Shopify preview mode
Common Issues
”No discount applied”
Possible causes:- Conditions not met
- Wrong path in condition
- Case-sensitive string comparison
- Empty selector result
- Check input data matches condition
- Verify field paths exist
- Test with simplified conditions
- Add facts to inspect intermediate values
”Wrong discount amount”
Possible causes:discount_typemismatch (percentage vs fixed)- Value format incorrect
appliesToEachItemconfusion
- Verify
discount_typeis correct - Check value is numeric
- Test with round numbers first
”Discount on wrong products”
Possible causes:- Selector returns unexpected results
- Handle doesn’t match
- GID format issue
- Test selector in facts
- Verify product handles
- Check variant IDs
Testing Best Practices
Start Simple
Begin with minimal configuration:Add Complexity Gradually
Once basic rule works, add:- Additional conditions
- Facts
- Complex selectors
- Multiple events
Test Edge Cases
- Empty cart
- Single item
- Large quantity
- Zero-price items
- Customer without account
Document Test Cases
Keep a record of test scenarios:Performance Testing
Monitor Execution Time
- Keep rules simple when possible
- Limit fact complexity
- Use direct targeting over selectors
- Test with realistic cart sizes
Stress Testing
Test with:- Large carts (20+ line items)
- Complex product structures
- Multiple rules
- Heavy fact computations
Next Steps
- Common Patterns - Real-world tested examples
- Troubleshooting - Detailed error solutions
- Performance - Optimization guide
