uppy
Version:
Extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:
48 lines (38 loc) • 1.12 kB
JavaScript
const DefaultStore = require('./DefaultStore')
describe('DefaultStore', () => {
it('can be created with or without new', () => {
let store = DefaultStore()
expect(typeof store).toBe('object')
store = new DefaultStore()
expect(typeof store).toBe('object')
})
it('merges in state using `setState`', () => {
const store = DefaultStore()
expect(store.getState()).toEqual({})
store.setState({
a: 1,
b: 2
})
expect(store.getState()).toEqual({ a: 1, b: 2 })
store.setState({ b: 3 })
expect(store.getState()).toEqual({ a: 1, b: 3 })
})
it('notifies subscriptions when state changes', () => {
let expected = []
let calls = 0
function listener (prevState, nextState, patch) {
calls++
expect([ prevState, nextState, patch ]).toEqual(expected)
}
const store = DefaultStore()
store.subscribe(listener)
expected = [{}, { a: 1, b: 2 }, { a: 1, b: 2 }]
store.setState({
a: 1,
b: 2
})
expected = [{ a: 1, b: 2 }, { a: 1, b: 3 }, { b: 3 }]
store.setState({ b: 3 })
expect(calls).toBe(2)
})
})