From 5ecec5e8d128d59a26cdb128b7b4d114a62adc09 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Sat, 28 Sep 2024 22:17:59 +0100 Subject: [PATCH] refactor: `callsToWrapUnions` --- test/test_types.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/test/test_types.js b/test/test_types.js index 7d5d2380..4578d7d2 100644 --- a/test/test_types.js +++ b/test/test_types.js @@ -3522,7 +3522,9 @@ suite('types', () => { }; const animalTypes = [Dog, Cat]; + let callsToWrapUnions = 0; const wrapUnions = (types) => { + callsToWrapUnions++; assert.deepEqual(types.map(t => t.name), ['Dog', 'Cat']); return (animal) => { const animalType = ((animal) => { @@ -3537,19 +3539,10 @@ suite('types', () => { } }; - // TODO: replace this with a mock when available - // currently we're on mocha without sinon - function mockWrapUnions() { - mockWrapUnions.calls = typeof mockWrapUnions.calls === 'undefined' - ? 1 - : ++mockWrapUnions.calls; - return wrapUnions.apply(null, arguments); - } - // Ambiguous, but we have a projection function - const Animal = Type.forSchema(animalTypes, { wrapUnions: mockWrapUnions }); + const Animal = Type.forSchema(animalTypes, { wrapUnions }); Animal.toBuffer({ meow: '🐈' }); - assert.equal(mockWrapUnions.calls, 1); + assert.equal(callsToWrapUnions, 1); assert.throws(() => Animal.toBuffer({ snap: '🐊' }), /Unknown animal/) });