diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/mock-scope.js | |
parent | Initial commit. (diff) | |
download | node-undici-upstream.tar.xz node-undici-upstream.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/mock-scope.js')
-rw-r--r-- | test/mock-scope.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/mock-scope.js b/test/mock-scope.js new file mode 100644 index 0000000..605ba58 --- /dev/null +++ b/test/mock-scope.js @@ -0,0 +1,73 @@ +'use strict' + +const { test } = require('tap') +const { MockScope } = require('../lib/mock/mock-interceptor') +const { InvalidArgumentError } = require('../lib/core/errors') + +test('MockScope - delay', t => { + t.plan(2) + + t.test('should return MockScope', t => { + t.plan(1) + const mockScope = new MockScope({ + path: '', + method: '' + }, []) + const result = mockScope.delay(200) + t.type(result, MockScope) + }) + + t.test('should error if passed options invalid', t => { + t.plan(4) + + const mockScope = new MockScope({ + path: '', + method: '' + }, []) + t.throws(() => mockScope.delay(), new InvalidArgumentError('waitInMs must be a valid integer > 0')) + t.throws(() => mockScope.delay(200.1), new InvalidArgumentError('waitInMs must be a valid integer > 0')) + t.throws(() => mockScope.delay(0), new InvalidArgumentError('waitInMs must be a valid integer > 0')) + t.throws(() => mockScope.delay(-1), new InvalidArgumentError('waitInMs must be a valid integer > 0')) + }) +}) + +test('MockScope - persist', t => { + t.plan(1) + + t.test('should return MockScope', t => { + t.plan(1) + const mockScope = new MockScope({ + path: '', + method: '' + }, []) + const result = mockScope.persist() + t.type(result, MockScope) + }) +}) + +test('MockScope - times', t => { + t.plan(2) + + t.test('should return MockScope', t => { + t.plan(1) + const mockScope = new MockScope({ + path: '', + method: '' + }, []) + const result = mockScope.times(200) + t.type(result, MockScope) + }) + + t.test('should error if passed options invalid', t => { + t.plan(4) + + const mockScope = new MockScope({ + path: '', + method: '' + }, []) + t.throws(() => mockScope.times(), new InvalidArgumentError('repeatTimes must be a valid integer > 0')) + t.throws(() => mockScope.times(200.1), new InvalidArgumentError('repeatTimes must be a valid integer > 0')) + t.throws(() => mockScope.times(0), new InvalidArgumentError('repeatTimes must be a valid integer > 0')) + t.throws(() => mockScope.times(-1), new InvalidArgumentError('repeatTimes must be a valid integer > 0')) + }) +}) |