Skip to content

Commit 274b427

Browse files
committed
[null] Improve test clarity with expect.assertions and descriptive parameter names
1 parent 47647ea commit 274b427

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

test/unit/core/store/store-nulls.test.ts

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -196,65 +196,50 @@ describe('Null listeners and events', () => {
196196
});
197197

198198
test('Cell listener fires when setting to null', () => {
199-
let called = 0;
200-
let newCell;
201-
let oldCell;
202-
store.addCellListener('t1', 'r1', 'c1', (_store, _t, _r, _c, nCell, oCell) => {
203-
called++;
204-
newCell = nCell;
205-
oldCell = oCell;
199+
expect.assertions(2);
200+
store.addCellListener('t1', 'r1', 'c1', (_store, _table, _row, _cell, newCell, oldCell) => {
201+
expect(newCell).toBe(null);
202+
expect(oldCell).toBeUndefined();
206203
});
207204

208205
store.setCell('t1', 'r1', 'c1', null);
209-
expect(called).toBe(1);
210-
expect(newCell).toBe(null);
211-
expect(oldCell).toBeUndefined();
212206
});
213207

214208
test('Cell listener fires when changing from null', () => {
215209
store.setCell('t1', 'r1', 'c1', null);
216-
let called = 0;
217-
let newCell;
218-
let oldCell;
219-
store.addCellListener('t1', 'r1', 'c1', (_store, _t, _r, _c, nCell, oCell) => {
220-
called++;
221-
newCell = nCell;
222-
oldCell = oCell;
210+
expect.assertions(2);
211+
store.addCellListener('t1', 'r1', 'c1', (_store, _table, _row, _cell, newCell, oldCell) => {
212+
expect(newCell).toBe('hello');
213+
expect(oldCell).toBe(null);
223214
});
224215

225216
store.setCell('t1', 'r1', 'c1', 'hello');
226-
expect(called).toBe(1);
227-
expect(newCell).toBe('hello');
228-
expect(oldCell).toBe(null);
229217
});
230218

231219
test('Value listener fires when setting to null', () => {
232-
let called = 0;
233-
let newValue;
234-
let oldValue;
235-
store.addValueListener('v1', (_store, _v, nValue, oValue) => {
236-
called++;
237-
newValue = nValue;
238-
oldValue = oValue;
220+
expect.assertions(2);
221+
store.addValueListener('v1', (_store, _valueId, newValue, oldValue) => {
222+
expect(newValue).toBe(null);
223+
expect(oldValue).toBeUndefined();
239224
});
240225

241226
store.setValue('v1', null);
242-
expect(called).toBe(1);
243-
expect(newValue).toBe(null);
244-
expect(oldValue).toBeUndefined();
245227
});
246228

247229
test('HasCell listener distinguishes null from deleted', () => {
248-
let calls: boolean[] = [];
249-
store.addHasCellListener('t1', 'r1', 'c1', (_store, _t, _r, _c, hasCell) => {
250-
calls.push(hasCell);
230+
expect.assertions(2);
231+
let callCount = 0;
232+
store.addHasCellListener('t1', 'r1', 'c1', (_store, _table, _row, _cell, hasCell) => {
233+
if (callCount === 0) {
234+
expect(hasCell).toBe(true);
235+
} else if (callCount === 1) {
236+
expect(hasCell).toBe(false);
237+
}
238+
callCount++;
251239
});
252240

253241
store.setCell('t1', 'r1', 'c1', null);
254-
expect(calls).toEqual([true]);
255-
256242
store.delCell('t1', 'r1', 'c1');
257-
expect(calls).toEqual([true, false]);
258243
});
259244
});
260245

0 commit comments

Comments
 (0)