-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 method for View Engine users to pass partial config
cashewConfig() enables View Engine users to pass partial config options in the module providers
- Loading branch information
theblushingcrow
committed
Aug 20, 2020
1 parent
3300fee
commit 7f7a934
Showing
3 changed files
with
49 additions
and
1 deletion.
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
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,31 @@ | ||
import { cashewConfig, defaultConfig } from '../httpCacheConfig'; | ||
|
||
describe('cashewConfig', () => { | ||
const responseSerializer = v => ''; | ||
|
||
it('should return the default config when called with an empty object', () => { | ||
expect(cashewConfig({})).toEqual(defaultConfig); | ||
}); | ||
|
||
it('should override the default config values when called with values in the config parameter', () => { | ||
const configWithStrategy = cashewConfig({ strategy: 'implicit' }); | ||
expect(configWithStrategy.ttl).toEqual(defaultConfig.ttl); | ||
expect(configWithStrategy.localStorageKey).toEqual(defaultConfig.localStorageKey); | ||
expect(configWithStrategy.strategy).toEqual('implicit'); | ||
|
||
const configWithTtl = cashewConfig({ ttl: 10000 }); | ||
expect(configWithTtl.localStorageKey).toEqual(defaultConfig.localStorageKey); | ||
expect(configWithTtl.strategy).toEqual(defaultConfig.strategy); | ||
expect(configWithTtl.ttl).toEqual(10000); | ||
|
||
const configWithLocalStorageKey = cashewConfig({ localStorageKey: 'x' }); | ||
expect(configWithLocalStorageKey.strategy).toEqual(defaultConfig.strategy); | ||
expect(configWithLocalStorageKey.ttl).toEqual(defaultConfig.ttl); | ||
expect(configWithLocalStorageKey.localStorageKey).toEqual('x'); | ||
}); | ||
|
||
it('should retain additional parameters passed in the config, such as responseSerializer', () => { | ||
const configWithResponseSerializer = cashewConfig({ responseSerializer }); | ||
expect(configWithResponseSerializer.responseSerializer({ a: 'a' })).toEqual(''); | ||
}); | ||
}); |