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
Copy file name to clipboardexpand all lines: docs/docs/testing.md
+101
Original file line number
Diff line number
Diff line change
@@ -1696,6 +1696,107 @@ Only the posts scenarios will be present in the database when running the `posts
1696
1696
1697
1697
During the run of any single test, there is only ever one scenario's worth of data present in the database: users.standard *or* users.incomplete.
1698
1698
1699
+
### describeScenario - a performance optimisation
1700
+
1701
+
The scenario feature described above should be the base starting point for setting up test that depend on the database. The scenario sets up the database before each scenario _test_, runs the test, and then tears down (deletes) the database scenario. This ensures that each of your tests are isolated, and that they do not affect each other.
1702
+
1703
+
**However**, there are some situations where you as the developer may want additional control regarding when the database is setup and torn down - maybe to run your test suite faster.
1704
+
1705
+
The `describeScenario` function is utilized to run a sequence of multiple tests, with a single database setup and tear-down.
1706
+
1707
+
```js
1708
+
// highlight-next-line
1709
+
describeScenario('contacts', (getScenario) => {
1710
+
// You can imagine the scenario setup happens here
1711
+
1712
+
// All these tests now use the same setup 👇
1713
+
it('xxx', () => {
1714
+
// Notice that the scenario has to be retrieved using the getter
1715
+
// highlight-next-line
1716
+
constscenario=getScenario()
1717
+
//...
1718
+
})
1719
+
1720
+
it('xxx', () => {
1721
+
constscenario=getScenario()
1722
+
/...
1723
+
})
1724
+
1725
+
})
1726
+
```
1727
+
1728
+
> **CAUTION**: With describeScenario, your tests are no longer isolated. The results, or side-effects, of prior tests can affect later tests.
1729
+
1730
+
Rationale for using `describeScenario` include:
1731
+
<ul>
1732
+
<li>Create multi-step tests where the next test is dependent upon the results of the previous test (Note caution above).</li>
1733
+
<li>Reduce testing run time. There is an overhead to setting up and tearing down the db on each test, and in some cases a reduced testing run time may be of significant benefit. This may be of benefit where the likelihood of side-effects is low, such as in query testing</li>
1734
+
</ul>
1735
+
1736
+
### describeScenario Examples
1737
+
1738
+
Following is an example of the use of `describeScenario` to speed up testing of a user query service function, where the risk of side-effects is low.
0 commit comments