|
| 1 | +import { NO_VALUE } from '../types' |
1 | 2 | import { createStaticFacet } from './createStaticFacet' |
2 | 3 |
|
3 | | -describe('createStaticFacet', () => { |
4 | | - it(`it can be read but not mutated`, () => { |
5 | | - const initialValue = {} |
6 | | - const mock = createStaticFacet(initialValue) |
| 4 | +it('allows reading, but not mutation', () => { |
| 5 | + const initialValue = {} |
| 6 | + const mock = createStaticFacet(initialValue) |
7 | 7 |
|
8 | | - expect(mock.get()).toBe(initialValue) |
9 | | - expect('set' in mock).toBe(false) |
10 | | - }) |
| 8 | + expect(mock.get()).toBe(initialValue) |
| 9 | + expect('set' in mock).toBe(false) |
| 10 | +}) |
| 11 | + |
| 12 | +it('responds with the same value if you observe it and warns you in a non-production environment', () => { |
| 13 | + const update = jest.fn() |
| 14 | + const initialValue = {} |
| 15 | + const mock = createStaticFacet(initialValue) |
11 | 16 |
|
12 | | - it(`it responds with the same value if you observe it and warns you in a non-production environment`, () => { |
13 | | - const update = jest.fn() |
14 | | - const initialValue = {} |
15 | | - const mock = createStaticFacet(initialValue) |
| 17 | + mock.observe(update) |
| 18 | + expect(update).toHaveBeenCalledTimes(1) |
| 19 | + expect(update).toHaveBeenCalledWith(initialValue) |
16 | 20 |
|
17 | | - mock.observe(update) |
18 | | - expect(update).toHaveBeenCalledTimes(1) |
19 | | - expect(update).toHaveBeenCalledWith(initialValue) |
| 21 | + update.mockClear() |
| 22 | + |
| 23 | + mock.observe(update) |
| 24 | + expect(update).toHaveBeenCalledTimes(1) |
| 25 | + expect(update).toHaveBeenCalledWith(initialValue) |
| 26 | +}) |
20 | 27 |
|
21 | | - update.mockClear() |
| 28 | +it('avoids triggering the listener if initialized with NO_VALUE', () => { |
| 29 | + const update = jest.fn() |
| 30 | + const initialValue = NO_VALUE |
| 31 | + const mock = createStaticFacet(initialValue) |
22 | 32 |
|
23 | | - mock.observe(update) |
24 | | - expect(update).toHaveBeenCalledTimes(1) |
25 | | - expect(update).toHaveBeenCalledWith(initialValue) |
26 | | - }) |
| 33 | + mock.observe(update) |
| 34 | + expect(update).not.toHaveBeenCalled() |
27 | 35 | }) |
0 commit comments