Skip to content

Instantly share code, notes, and snippets.

@innerdaze
Created April 20, 2018 09:17
Show Gist options
  • Save innerdaze/23880eac0b3444b5efdd9d30e5c35258 to your computer and use it in GitHub Desktop.
Save innerdaze/23880eac0b3444b5efdd9d30e5c35258 to your computer and use it in GitHub Desktop.
Example Selector Unit Test
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import * as selectors from '../selectors'
const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)
describe('INVENTORY/SELECTORS', () => {
test('barcode to product lookup works', () => {
const mockProduct = {
ProductID: 'ABC'
}
const store = mockStore({
product: {
productEntities: {
ABC: mockProduct
}
},
barcode: {
barcodeEntities: {
1234: {
Barcode: 1234,
ProductID: 'ABC'
}
}
}
})
const product = selectors.productByBarcodeSelector(store.getState(), 1234)
expect(product).toEqual(mockProduct)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment