-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: allow numeric values as CacheContextKey
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
projects/ngneat/cashew/src/lib/specs/key-serializer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { DefaultKeySerializer } from '../key-serializer'; | ||
import { httpRequest } from './mocks'; | ||
|
||
describe('key serializer', () => { | ||
it('serializes to string using the given number', () => { | ||
const serializer = new DefaultKeySerializer(); | ||
const key = serializer.serialize(null, { key: 2 }); | ||
expect(key).toEqual('2'); | ||
}); | ||
|
||
it('serializes to string using the given string', () => { | ||
const serializer = new DefaultKeySerializer(); | ||
const key = serializer.serialize(null, { key: 'hello' }); | ||
expect(key).toEqual('hello'); | ||
}); | ||
|
||
it('serializes to string using the given number producing function', () => { | ||
const serializer = new DefaultKeySerializer(); | ||
const key = serializer.serialize(null, { key: () => 2 + 2 }); | ||
expect(key).toEqual('4'); | ||
}); | ||
|
||
it('serializes to string using the given string producing function', () => { | ||
const serializer = new DefaultKeySerializer(); | ||
const key = serializer.serialize(null, { key: () => 'hello' + 'world' }); | ||
expect(key).toEqual('helloworld'); | ||
}); | ||
|
||
it('serializes to full url including parameters if key is absent', () => { | ||
const serializer = new DefaultKeySerializer(); | ||
const request = httpRequest(); | ||
const key = serializer.serialize(request, {}); | ||
expect(key).toEqual(request.urlWithParams); | ||
}); | ||
}); |