Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/graphql-hooks-memcache/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import memCache from '../src'

describe('memcache', () => {
let cache
beforeEach(() => {
cache = memCache()
})
it('sets and gets key wtih string key', () => {
cache.set('foo', 'bar')
expect(cache.get('foo')).toEqual('bar')
})
it('sets and gets key with object key', () => {
cache.set({ foo: 'foo' }, 'baz')
expect(cache.get({ foo: 'foo' })).toEqual('baz')
})
it('deletes a key', () => {
cache.set('foo', 'baz')
expect(cache.get('foo')).toEqual('baz')
cache.delete('foo')
expect(cache.get('foo')).toBe(undefined)
})
it('lists all keys', () => {
cache.set('foo', 'bar')
cache.set('bar', 'baz')
expect(cache.keys().length).toEqual(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert the return value instead of or as well as the length?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what the keys are though as their generated so can't assert on them.

})
it('clears all keys', () => {
cache.set('foo', 'bar')
cache.set('bar', 'baz')
expect(cache.keys().length).toEqual(2)
cache.clear()
expect(cache.keys().length).toEqual(0)
})
it('returns initial state', () => {
cache = memCache({ initialState: { foo: 'bar' } })
expect(cache.getInitialState()).toEqual({ foo: 'bar' })
})
})