Skip to main content

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

  1. Navigate to Apps → Function Lab
  2. Select your function
  3. Click “Preview” or “Test”
  4. 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:
  1. Conditions not met
  2. Wrong path in condition
  3. Case-sensitive string comparison
  4. Empty selector result
Debug steps:
  • Check input data matches condition
  • Verify field paths exist
  • Test with simplified conditions
  • Add facts to inspect intermediate values

”Wrong discount amount”

Possible causes:
  1. discount_type mismatch (percentage vs fixed)
  2. Value format incorrect
  3. appliesToEachItem confusion
Debug steps:
  • Verify discount_type is correct
  • Check value is numeric
  • Test with round numbers first

”Discount on wrong products”

Possible causes:
  1. Selector returns unexpected results
  2. Handle doesn’t match
  3. GID format issue
Debug steps:
  • 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:
  1. Additional conditions
  2. Facts
  3. Complex selectors
  4. 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