Skip to content

Commit 79eadf7

Browse files
committed
doc(test): document method overrides
1 parent 05b9c74 commit 79eadf7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/backend/tools/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,33 @@ class ExampleService extends BaseService {
6767
| `assert.equal` | `actual`, `expected`, `message` | `actual: any`, `expected: any`, `message: string` | Asserts that `actual === expected`. The final parameter is a short descriptive message for the test rule. |
6868

6969

70+
#### Overriding Service Methods
71+
72+
When running under the test kernel, services have the mode
73+
`{ override_prefix: '__test_' }`. This means whenever `some_method` is called
74+
within the service, `__test_some_method` will be called instead if it is
75+
defined. For example, in the following service we
76+
77+
```javascript
78+
class TestService extends BaseService {
79+
normal_method () {
80+
return 3;
81+
}
82+
method_to_mock () {
83+
return 5;
84+
}
85+
86+
__test_method_to_mock () {
87+
return 7;
88+
}
89+
90+
_test ({ assert }) {
91+
// This assertion will pass
92+
assert.equal(this.normal_method(), 3);
93+
assert.equal(this.method_to_mock(), 7);
94+
}
95+
}
96+
```
7097

7198
### Test Kernel Notes
7299

0 commit comments

Comments
 (0)