From 48d4f890d7ba61af91c8a58377fbb71e17ceea8b Mon Sep 17 00:00:00 2001 From: Manish Jethani Date: Sun, 15 Aug 2021 20:46:57 +0530 Subject: [PATCH] Add tests for SNFE initialization (#3823) --- platform/npm/tests/snfe.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/platform/npm/tests/snfe.js b/platform/npm/tests/snfe.js index a4b29e2cc..f6823ce84 100644 --- a/platform/npm/tests/snfe.js +++ b/platform/npm/tests/snfe.js @@ -39,6 +39,36 @@ process.on('warning', warning => { let engine = null; describe('SNFE', () => { + describe('Initialization', () => { + let StaticNetFilteringEngine = null; + + beforeEach(async () => { + const module = await createWorld('./index.js', { globals: { URL } }); + + StaticNetFilteringEngine = module.StaticNetFilteringEngine; + }); + + it('should not reject on first attempt', async () => { + await StaticNetFilteringEngine.create(); + }); + + it('should reject on second attempt', async () => { + await StaticNetFilteringEngine.create(); + await assert.rejects(StaticNetFilteringEngine.create()); + }); + + it('should reject on third attempt', async () => { + await StaticNetFilteringEngine.create(); + + try { + await StaticNetFilteringEngine.create(); + } catch (error) { + } + + await assert.rejects(StaticNetFilteringEngine.create()); + }); + }); + describe('Filter loading', () => { beforeEach(async () => { const globals = { URL, setTimeout, clearTimeout };