Commit ec20d9c
authored
Dictionary (New Word): Snapshot (#82)
# Word
#### Snapshot
# Meaning/Definition
A snapshot is a saved state or image of a system, database, or file at a
particular point in time.
In software development and testing, a snapshot is used to capture the
exact state of an application or component at a specific moment. This
can be useful for comparing changes over time or ensuring that the
output of a function or the state of a component remains consistent.
For example, when testing a user interface component, a snapshot can
save the rendered output. Future tests can then compare the current
output with the saved snapshot to ensure that no unintended changes have
occurred.
**Simple Code Example** (JavaScript using Jest):
```javascript
import renderer from 'react-test-renderer';
import MyComponent from './MyComponent';
test('MyComponent renders correctly', () => {
const tree = renderer.create(<MyComponent />).toJSON();
expect(tree).toMatchSnapshot();
});
```
In this example, `renderer.create` renders the `MyComponent` and saves
its output as a JSON object. The `toMatchSnapshot` function then
compares this output to a previously saved snapshot. If the output has
changed, the test will fail, indicating that the component's output is
different from what was expected.1 parent 1c0089e commit ec20d9c
1 file changed
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments