Skip to content

Commit fb4313e

Browse files
committed
Tidy up store tests
1 parent f5101c0 commit fb4313e

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

packages/svelte/tests/store/test.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('writable', () => {
2222
assert.deepEqual(values, [0, 1, 2]);
2323
});
2424

25-
it('creates an undefined writable store', () => {
25+
it('creates an `undefined` writable store', () => {
2626
const store = writable();
2727

2828
const values: unknown[] = [];
@@ -41,7 +41,9 @@ describe('writable', () => {
4141

4242
const store = writable(0, () => {
4343
called += 1;
44-
return () => (called -= 1);
44+
return () => {
45+
called -= 1;
46+
};
4547
});
4648

4749
const unsubscribe1 = store.subscribe(() => {});
@@ -81,16 +83,20 @@ describe('writable', () => {
8183
let count1 = 0;
8284
let count2 = 0;
8385

84-
store.subscribe(() => (count1 += 1))();
86+
store.subscribe(() => {
87+
count1 += 1;
88+
})();
8589
assert.equal(count1, 1);
8690

87-
const unsubscribe = store.subscribe(() => (count2 += 1));
91+
const unsubscribe = store.subscribe(() => {
92+
count2 += 1;
93+
});
8894
assert.equal(count2, 1);
8995

9096
unsubscribe();
9197
});
9298

93-
it('no error even if unsubscribe calls twice', () => {
99+
it('does not throw an error if `unsubscribe` is called more than once', () => {
94100
let num = 0;
95101
const store = writable(num, (set) => set((num += 1)));
96102
const unsubscribe = store.subscribe(() => {});
@@ -139,7 +145,7 @@ describe('readable', () => {
139145
assert.deepEqual(values, [0, 1, 2]);
140146
});
141147

142-
it('passes an optional update function', () => {
148+
it('passes an optional `update` function', () => {
143149
let running;
144150

145151
let tick = (value: any) => {};
@@ -186,7 +192,7 @@ describe('readable', () => {
186192
assert.deepEqual(values, [0, 1, 2, 5, 9, 5, 11]);
187193
});
188194

189-
it('creates an undefined readable store', () => {
195+
it('creates an `undefined` readable store', () => {
190196
const store = readable();
191197

192198
const values: unknown[] = [];
@@ -270,7 +276,7 @@ describe('derived', () => {
270276
assert.deepEqual(values, [6, 12, 20]);
271277
});
272278

273-
it('passes optional set function', () => {
279+
it('passes optional `set` function', () => {
274280
const number = writable(1);
275281
const evens = derived(
276282
number,
@@ -301,9 +307,9 @@ describe('derived', () => {
301307
assert.deepEqual(values, [0, 2, 4]);
302308
});
303309

304-
it('passes optional set and update functions', () => {
310+
it('passes optional `set` and `update` functions', () => {
305311
const number = writable(1);
306-
const evensAndSquaresOf4 = derived(
312+
const evens_and_squares_of_4 = derived(
307313
number,
308314
// @ts-expect-error TODO feels like inference should work here
309315
(n, set, update) => {
@@ -316,7 +322,7 @@ describe('derived', () => {
316322

317323
const values: number[] = [];
318324

319-
const unsubscribe = evensAndSquaresOf4.subscribe((value) => {
325+
const unsubscribe = evens_and_squares_of_4.subscribe((value) => {
320326
values.push(value);
321327
});
322328

@@ -341,21 +347,21 @@ describe('derived', () => {
341347
});
342348

343349
it('prevents glitches', () => {
344-
const lastname = writable('Jekyll');
350+
const last_name = writable('Jekyll');
345351

346352
// @ts-expect-error TODO feels like inference should work here
347-
const firstname = derived(lastname, (n) => (n === 'Jekyll' ? 'Henry' : 'Edward'));
353+
const first_name = derived(last_name, (n) => (n === 'Jekyll' ? 'Henry' : 'Edward'));
348354

349355
// @ts-expect-error TODO feels like inference should work here
350-
const fullname = derived([firstname, lastname], (names) => names.join(' '));
356+
const full_name = derived([first_name, last_name], (names) => names.join(' '));
351357

352358
const values: string[] = [];
353359

354-
const unsubscribe = fullname.subscribe((value) => {
360+
const unsubscribe = full_name.subscribe((value) => {
355361
values.push(value as string);
356362
});
357363

358-
lastname.set('Hyde');
364+
last_name.set('Hyde');
359365

360366
assert.deepEqual(values, ['Henry Jekyll', 'Edward Hyde']);
361367

@@ -364,7 +370,6 @@ describe('derived', () => {
364370

365371
it('prevents diamond dependency problem', () => {
366372
const count = writable(0);
367-
368373
const values: string[] = [];
369374

370375
// @ts-expect-error TODO feels like inference should work here
@@ -421,7 +426,7 @@ describe('derived', () => {
421426
unsubscribe();
422427
});
423428

424-
it('is updated with safe_not_equal logic', () => {
429+
it('is updated with `safe_not_equal` logic', () => {
425430
const arr = [0];
426431

427432
const number = writable(1);
@@ -446,7 +451,7 @@ describe('derived', () => {
446451
unsubscribe();
447452
});
448453

449-
it('calls a cleanup function', () => {
454+
it('calls a `cleanup` function', () => {
450455
const num = writable(1);
451456

452457
const values: number[] = [];
@@ -523,7 +528,7 @@ describe('derived', () => {
523528
assert.equal(get(d), 42);
524529
});
525530

526-
it("doesn't restart when unsubscribed from another store with a shared ancestor", () => {
531+
it('does not restart when unsubscribed from another store with a shared ancestor', () => {
527532
const a = writable(true);
528533
let b_started = false;
529534

@@ -577,17 +582,17 @@ describe('get', () => {
577582

578583
describe('readonly', () => {
579584
it('makes a store readonly', () => {
580-
const writableStore = writable(1);
581-
const readableStore = readonly(writableStore);
585+
const writable_store = writable(1);
586+
const readable_store = readonly(writable_store);
582587

583-
assert.equal(get(readableStore), get(writableStore));
588+
assert.equal(get(readable_store), get(writable_store));
584589

585-
writableStore.set(2);
590+
writable_store.set(2);
586591

587-
assert.equal(get(readableStore), 2);
588-
assert.equal(get(readableStore), get(writableStore));
592+
assert.equal(get(readable_store), 2);
593+
assert.equal(get(readable_store), get(writable_store));
589594

590595
// @ts-ignore
591-
assert.throws(() => readableStore.set(3));
596+
assert.throws(() => readable_store.set(3));
592597
});
593598
});

0 commit comments

Comments
 (0)