This repository was archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.spec.js
More file actions
58 lines (50 loc) · 1.69 KB
/
index.spec.js
File metadata and controls
58 lines (50 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import middleware, { createLogAction, createCaptureAction } from './index'
describe('redux-rollbar-log-middleware', () => {
let rollbarMock
let store
let next
const dispatch = action => middleware(rollbarMock)(store)(next)(action)
beforeEach(() => {
rollbarMock = {
debug: jest.fn(),
info: jest.fn(),
captureEvent: jest.fn(),
}
store = {}
next = jest.fn()
})
it('should ignore the action that dont have the right type', () => {
const action = { type: 'SOME_ACTION' }
dispatch(action)
expect(next.mock.calls.length).toBe(1)
expect(next.mock.calls[0][0]).toBe(action)
expect(rollbarMock.debug.mock.calls.length).toBe(0)
})
describe('createLogAction', () => {
it('should invoke the rollbar log when receive the right action', () => {
const logPayload = {
type: 'info',
message: 'test',
body: { a: 'test' }
}
const action = createLogAction(logPayload)
dispatch(action)
expect(next.mock.calls.length).toBe(0)
expect(rollbarMock.info.mock.calls.length).toBe(1)
expect(rollbarMock.info.mock.calls[0]).toEqual([logPayload.message, logPayload.body])
})
})
describe('createCaptureAction', () => {
it('should invoke the rollbar captureEvent when receive the right action', () => {
const capturePayload = {
type: 'info',
body: { a: 'test' }
}
const action = createCaptureAction(capturePayload)
dispatch(action)
expect(next.mock.calls.length).toBe(0)
expect(rollbarMock.captureEvent.mock.calls.length).toBe(1)
expect(rollbarMock.captureEvent.mock.calls[0]).toEqual([capturePayload.body, capturePayload.type])
})
})
})