Skip to content

Commit

Permalink
feature(linter): added tests for onMessage listener
Browse files Browse the repository at this point in the history
  • Loading branch information
capJavert committed Aug 23, 2019
1 parent fa847ad commit 0e5b7bc
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ it('should prefetch comments on init', () => {
browser.runtime.sendMessage = (message) => {
if (message.name === 'comments') {
commentsMessage = message
browser.runtime.onMessage.listener({ name: 'comments', value: dictionary })
}
}

const agent = createAgent()
clippyController.init(agent)

expect(commentsMessage).toEqual({ name: 'comments' })

browser.runtime.onMessage.listener({ name: 'comments', value: dictionary })

expect(clippyController.comments).toEqual(dictionary)
})

Expand Down Expand Up @@ -159,3 +157,52 @@ test('animation trigger', () => {
expect(agent.animationLength).toEqual(5000)
expect(agent.callback).toBeDefined()
})

test('isActive listener', () => {
expect.assertions(2)

const agent = createAgent()
clippyController.init(agent)

browser.runtime.onMessage.listener({ name: 'isActive', value: true })

expect(agent.isActive).toBe(true)

browser.runtime.onMessage.listener({ name: 'isActive', value: false })

expect(agent.isActive).toBe(false)
})

test('comments listener', () => {
const agent = createAgent()
clippyController.init(agent)

browser.runtime.onMessage.listener({ name: 'comments', value: dictionary })

expect(clippyController.comments).toEqual(dictionary)
})

test('animate listener', () => {
expect.assertions(2)

const agent = createAgent()
clippyController.init(agent)

browser.runtime.sendMessage = (message, callback) => {
if (message.name === 'isActive') {
callback({ value: false })
}
}
browser.runtime.onMessage.listener({ name: 'animate' })

expect(agent.animation).toBeUndefined()

browser.runtime.sendMessage = (message, callback) => {
if (message.name === 'isActive') {
callback({ value: true })
}
}
browser.runtime.onMessage.listener({ name: 'animate' })

expect(agent.animation).toBeDefined()
})

0 comments on commit 0e5b7bc

Please sign in to comment.