Skip to content

Commit 6bdebef

Browse files
committed
Add tests for getFromUrl and update imports
Added unit tests for getFromUrl to verify correct value extraction and error handling. Updated imports in error classes to use named import for CustomError. Added @std/assert to deno.json imports for testing.
1 parent 095a22a commit 6bdebef

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

deno.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@
4747
"no-inferrable-types"
4848
]
4949
}
50+
},
51+
"imports": {
52+
"@std/assert": "jsr:@std/assert@^1.0.15"
5053
}
5154
}

deno.lock

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/request_url/error/missing_url_parameter_key_error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import CustomError from '../../error/custom_error.ts'
1+
import { CustomError } from '../../error/custom_error.ts'
22

33
/**
44
* This class represents a missing URL parameters error. This error is thrown if there is a missing URL parameter.

src/request_url/error/missing_url_parameter_value_error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import CustomError from '../../error/custom_error.ts'
1+
import { CustomError } from '../../error/custom_error.ts'
22

33
/**
44
* This class represents a missing URL parameters error. This error is thrown if there is a missing URL parameter.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { assertEquals, assertIsError } from '@std/assert'
2+
import { getFromUrl } from './index.ts';
3+
import {MissingURLParameterKeyError} from '../error/index.ts';
4+
5+
Deno.test('Test getFromUrl', async (test) => {
6+
await test.step({
7+
name: 'Test if key gets queried correctly.',
8+
fn() : void {
9+
assertEquals(getFromUrl('key=value1&key=value2', 'key'), ['value1', 'value2'])
10+
}
11+
})
12+
13+
await test.step({
14+
name: 'Test if function throws if the key does not exist.',
15+
fn() : void {
16+
assertIsError(getFromUrl('key=value1&key=value2', 'keyDoesNotExist'), MissingURLParameterKeyError)
17+
}
18+
})
19+
})

0 commit comments

Comments
 (0)