Skip to content

Commit

Permalink
Fix incorrect test for applyStatusChange
Browse files Browse the repository at this point in the history
Boy, this took me a while. The main problem was
that applyStatusChange is async, which I hadn't
taken into account. Therefore, the assertion was
run before applyStatusChange had done its work.
Stupid error of me.

I also made some mistakes for the tabId: I didn't
resolve the browser.tabs.query-mock with the variable,
but with a hand coded integer.

What made this even more frustrating to debug, was a bug
in Sinon I found through this: comparing '1234' to 1234
gave a very confusing AssertionError message, as if
everything was okay. See sinonjs/sinon#2084
for the bug I filed.
  • Loading branch information
rensbaardman committed Sep 19, 2019
1 parent 237e029 commit 2380a46
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/unit/apply_utils.test.js
Expand Up @@ -577,9 +577,9 @@ describe('apply_utils', function() {

})

describe.only('applyStatusChange', () => {
describe('applyStatusChange', () => {

it('removes all rules when new status is false', () => {
it('removes all rules when new status is false', async () => {

const applyStatusChange = apply_utils.__get__('applyStatusChange')

Expand All @@ -588,8 +588,10 @@ describe('apply_utils', function() {
getConfigMock.resolves({categories: categoriesMock})
apply_utils.__set__('getConfig', getConfigMock)

const host = 'my-host.com'
const tabId = 1234
const browserTabsQueryMock = sinon.stub()
browserTabsQueryMock.resolves([{id: 1234}])
browserTabsQueryMock.resolves([{id: tabId}])

// somehow I can't get browser_stub to work here...
const browserStub = { tabs: {
Expand All @@ -598,8 +600,7 @@ describe('apply_utils', function() {

apply_utils.__set__('browser', browserStub)

const host = 'my-host.com'
const tabId = '1234'


const newSettings = {
_status: false
Expand All @@ -612,7 +613,7 @@ describe('apply_utils', function() {
let removeAllSpy = sinon.spy();
apply_utils.__set__('removeAll', removeAllSpy)

applyStatusChange(host, newSettings, status)
await applyStatusChange(host, newSettings, status)

assert.calledOnce(removeAllSpy)
assert.calledWith(removeAllSpy, categoriesMock, tabId, force=true)
Expand Down

0 comments on commit 2380a46

Please sign in to comment.