Skip to content

Commit

Permalink
jest: Prepare for eslint-plugin-jest upgrade.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbobbe committed Sep 16, 2020
1 parent 9a144c5 commit 3f9892d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
21 changes: 17 additions & 4 deletions src/__tests__/sentry-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,33 @@ describe('sentry', () => {
// we're specifically testing that its entry points can be used while it's
// uninitialized.
beforeEach(() => {
// This Jest lint rule is slightly concerning; its doc [1]
// claims that `expect` statements won't run if they're outside
// a `test` or `it` block. Empirically, here, that isn't true --
// changing the below assertion to its negation causes quite
// visible failure output from Jest.
//
// [1] https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-standalone-expect.md
// eslint-disable-next-line jest/no-standalone-expect
expect(isSentryActive()).toBeFalse();
});

afterEach(() => {
// (see above)
// eslint-disable-next-line jest/no-standalone-expect
expect(isSentryActive()).toBeFalse();
});

test('breadcrumbs', () => {
Sentry.addBreadcrumb({
message: 'test message',
level: Sentry.Severity.Debug,
});
expect(() => {
Sentry.addBreadcrumb({
message: 'test message',
level: Sentry.Severity.Debug,
});
}).not.toThrow();
});

// eslint-disable-next-line jest/expect-expect
test('exception reporting', () => {
// The text here is intended to prevent some hypothetical future reader of
// Sentry event logs dismissing the error as harmless expected noise, in
Expand Down
3 changes: 3 additions & 0 deletions src/emoji/__tests__/data-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* @flow strict-local */
// Tell Jest to recognize `check` as a helper function that runs
// assertions.
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "check"] }] */
import { codeToEmojiMap, getFilteredEmojis } from '../data';

// Prettier disabled in .prettierignore ; it misparses this file, apparently
Expand Down
37 changes: 16 additions & 21 deletions src/message/__tests__/fetchActions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,14 @@ describe('fetchActions', () => {
};
fetch.mockResponseSuccess(JSON.stringify(response));

expect.assertions(2);
try {
await store.dispatch(
await expect(
store.dispatch(
fetchMessages({ narrow: HOME_NARROW, anchor: 0, numBefore: 1, numAfter: 1 }),
);
} catch (e) {
),
).rejects.toThrow(
// Update this with changes to the message string or error type.
expect(e.message).toBe('Active account not logged in');
}
new Error('Active account not logged in'),
);

const actions = store.getActions();

Expand Down Expand Up @@ -255,15 +254,14 @@ describe('fetchActions', () => {
};
fetch.mockResponseSuccess(JSON.stringify(response));

expect.assertions(2);
try {
await store.dispatch(
await expect(
store.dispatch(
fetchMessages({ narrow: HOME_NARROW, anchor: 0, numBefore: 1, numAfter: 1 }),
);
} catch (e) {
),
).rejects.toThrow(
// Update this with changes to the error type.
expect(e).toBeInstanceOf(TypeError);
}
TypeError,
);

const actions = store.getActions();

Expand All @@ -281,14 +279,11 @@ describe('fetchActions', () => {

fetch.mockResponseFailure(fetchError);

expect.assertions(1);
try {
await store.dispatch(
await expect(
store.dispatch(
fetchMessages({ narrow: HOME_NARROW, anchor: 0, numBefore: 1, numAfter: 1 }),
);
} catch (e) {
expect(e).toBe(fetchError);
}
),
).rejects.toThrow(fetchError);
});
});

Expand Down
13 changes: 13 additions & 0 deletions src/presence/__tests__/heartbeat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,31 @@ describe('Heartbeat', () => {

for (const heartbeat of heartbeats) {
// Tests should stop all their Heartbeats.
//
// This Jest lint rule is slightly concerning; its doc [1]
// claims that `expect` statements won't run if they're outside
// a `test` or `it` block. Empirically, here, that isn't true --
// changing the below assertion to its negation causes quite
// visible failure output from Jest.
//
// [1] https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-standalone-expect.md
// eslint-disable-next-line jest/no-standalone-expect
expect(heartbeat.isActive()).toBeFalse();
heartbeat.callback.mockClear();
}

// Stopped heartbeats may have timers running, but those timers should not
// persist beyond their next firing...
lolex.runOnlyPendingTimers();
// (see above, about lint rule)
// eslint-disable-next-line jest/no-standalone-expect
expect(lolex.getTimerCount()).toBe(0);

// ... and none of those _timer_ firings should result in a _callback_
// firing.
for (const heartbeat of heartbeats) {
// (see above, about lint rule)
// eslint-disable-next-line jest/no-standalone-expect
expect(heartbeat.callback).not.toHaveBeenCalled();
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/utils/__tests__/internalLinks-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* @flow strict-local */
// Tell Jest to recognize `expectStream` as a helper function that
// runs assertions.
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "expectStream"] }] */

import type { User } from '../../api/modelTypes';
import { streamNarrow, topicNarrow, groupNarrow, STARRED_NARROW } from '../narrow';
import {
Expand Down

0 comments on commit 3f9892d

Please sign in to comment.