Skip to content

Commit 6746fbb

Browse files
committed
update docs
1 parent 9480aee commit 6746fbb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/guide.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,40 @@ Function test_multiple_mock_calls($t : cs.Testing.Testing)
572572
$t.assert.areEqual($t; "guest"; $stat.getXCallYParameter(2; 1); "Second call should be guest")
573573
```
574574

575+
### ⚠️ **CRITICAL: Avoid `This` in Mock Formulas**
576+
577+
**Rule**: Never use `This` directly inside Formula expressions passed to `$t.stats.mock()`.
578+
579+
When the test runner calls `Formula.apply()` on test methods, it overrides the `This` context for all nested Formulas, causing `This` references to fail.
580+
581+
❌ **Wrong:**
582+
```4d
583+
$object._method:=Formula($t.stats.mock("_method"; Null; This.mockData))
584+
// This.mockData will be undefined due to context override
585+
```
586+
587+
✅ **Correct - Local variable capture:**
588+
```4d
589+
var $mockData : Variant
590+
$mockData:=This.mockData // Capture the value first
591+
$object._method:=Formula($t.stats.mock("_method"; Null; $mockData))
592+
```
593+
594+
✅ **Alternative - Formula parameters:**
595+
```4d
596+
$object._method:=Formula($t.stats.mock("_method"; Null; $1); This.mockData)
597+
```
598+
599+
**When This Applies:**
600+
- Mock formulas: `Formula($t.stats.mock(...))`
601+
- Any Formula passed to test framework methods
602+
- Any Formula that needs to access test class properties (`This.something`)
603+
604+
**Safe Usage:**
605+
- Local variables and parameters work fine in Formulas
606+
- `This` is safe in the main test method body, just not in nested Formulas
607+
- Test framework objects like `$t.stats` work normally
608+
575609
## CI/CD Integration
576610

577611
### GitHub Actions Example

0 commit comments

Comments
 (0)