fix(specs): fix FeatureUsage spec

Summary: Damn async TaskQueue

Test Plan: fixed

Reviewers: juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3888
This commit is contained in:
Evan Morikawa 2017-02-10 16:49:40 -05:00
parent 9c3dd29c10
commit f33667e1a1
2 changed files with 11 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import pathwatcher from 'pathwatcher'; import pathwatcher from 'pathwatcher';
import ReactTestUtils from 'react-addons-test-utils'; import ReactTestUtils from 'react-addons-test-utils';
import {TaskQueue} from 'nylas-exports'
// TODO the local-sync package should be moved as part of nylas-mail core, // TODO the local-sync package should be moved as part of nylas-mail core,
// instead of being a separate package // instead of being a separate package
import {destroyTestDatabase} from '../../internal_packages/local-sync/spec/helpers' import {destroyTestDatabase} from '../../internal_packages/local-sync/spec/helpers'
@ -29,6 +30,11 @@ class MasterAfterEach {
NylasEnv.styles.restoreSnapshot(styleElementsToRestore); NylasEnv.styles.restoreSnapshot(styleElementsToRestore);
this.removeAllSpies(); this.removeAllSpies();
if (TaskQueue._queue.length > 0) {
console.inspect(TaskQueue._queue)
TaskQueue._queue = []
throw new Error("Your test forgot to clean up the TaskQueue")
}
waits(0); waits(0);
}); // yield to ui thread to make screen update more frequently }); // yield to ui thread to make screen update more frequently
} }

View file

@ -1,4 +1,4 @@
import {TaskQueueStatusStore} from 'nylas-exports' import {TaskQueue, TaskQueueStatusStore} from 'nylas-exports'
import FeatureUsageStore from '../../src/flux/stores/feature-usage-store' import FeatureUsageStore from '../../src/flux/stores/feature-usage-store'
import Task from '../../src/flux/tasks/task' import Task from '../../src/flux/tasks/task'
import SendFeatureUsageEventTask from '../../src/flux/tasks/send-feature-usage-event-task' import SendFeatureUsageEventTask from '../../src/flux/tasks/send-feature-usage-event-task'
@ -53,6 +53,10 @@ describe("FeatureUsageStore", function featureUsageStoreSpec() {
spyOn(TaskQueueStatusStore, "waitForPerformLocal").andReturn(Promise.resolve()) spyOn(TaskQueueStatusStore, "waitForPerformLocal").andReturn(Promise.resolve())
}); });
afterEach(() => {
TaskQueue._queue = []
})
it("returns the num remaining if successful", async () => { it("returns the num remaining if successful", async () => {
let numLeft = await FeatureUsageStore.useFeature('is-usable'); let numLeft = await FeatureUsageStore.useFeature('is-usable');
expect(numLeft).toBe(1) expect(numLeft).toBe(1)