Commit 52d8eed2 authored by Robert Knight's avatar Robert Knight

Use `mockImportedComponents` in several additional tests

For consistency with other tests, use `mockImportedComponents` so that
an issue with an imported component doesn't cause a cascade of failures
in the unit tests for these components.
parent f593f98b
...@@ -6,6 +6,7 @@ import { LinkType } from '../../markdown-commands'; ...@@ -6,6 +6,7 @@ import { LinkType } from '../../markdown-commands';
import MarkdownEditor from '../markdown-editor'; import MarkdownEditor from '../markdown-editor';
import { $imports } from '../markdown-editor'; import { $imports } from '../markdown-editor';
import mockImportedComponents from '../../../test-util/mock-imported-components';
import { checkAccessibility } from '../../../test-util/accessibility'; import { checkAccessibility } from '../../../test-util/accessibility';
describe('MarkdownEditor', () => { describe('MarkdownEditor', () => {
...@@ -32,6 +33,7 @@ describe('MarkdownEditor', () => { ...@@ -32,6 +33,7 @@ describe('MarkdownEditor', () => {
return null; return null;
}; };
$imports.$mock(mockImportedComponents());
$imports.$mock({ $imports.$mock({
'../markdown-commands': fakeMarkdownCommands, '../markdown-commands': fakeMarkdownCommands,
'./markdown-view': MarkdownView, './markdown-view': MarkdownView,
......
...@@ -4,6 +4,7 @@ import { createElement } from 'preact'; ...@@ -4,6 +4,7 @@ import { createElement } from 'preact';
import SearchInput from '../search-input'; import SearchInput from '../search-input';
import { $imports } from '../search-input'; import { $imports } from '../search-input';
import mockImportedComponents from '../../../test-util/mock-imported-components';
import { checkAccessibility } from '../../../test-util/accessibility'; import { checkAccessibility } from '../../../test-util/accessibility';
describe('SearchInput', () => { describe('SearchInput', () => {
...@@ -22,11 +23,8 @@ describe('SearchInput', () => { ...@@ -22,11 +23,8 @@ describe('SearchInput', () => {
beforeEach(() => { beforeEach(() => {
fakeStore = { isLoading: sinon.stub().returns(false) }; fakeStore = { isLoading: sinon.stub().returns(false) };
const FakeSpinner = () => null; $imports.$mock(mockImportedComponents());
FakeSpinner.displayName = 'Spinner';
$imports.$mock({ $imports.$mock({
'./spinner': FakeSpinner,
'../store/use-store': callback => callback(fakeStore), '../store/use-store': callback => callback(fakeStore),
}); });
}); });
...@@ -84,7 +82,7 @@ describe('SearchInput', () => { ...@@ -84,7 +82,7 @@ describe('SearchInput', () => {
it('renders search button when app is not in "loading" state', () => { it('renders search button when app is not in "loading" state', () => {
fakeStore.isLoading.returns(false); fakeStore.isLoading.returns(false);
const wrapper = createSearchInput(); const wrapper = createSearchInput();
assert.isTrue(wrapper.exists('button')); assert.isTrue(wrapper.exists('Button'));
}); });
it( it(
......
...@@ -4,6 +4,7 @@ import { createElement } from 'preact'; ...@@ -4,6 +4,7 @@ import { createElement } from 'preact';
import VersionInfo from '../version-info'; import VersionInfo from '../version-info';
import { $imports } from '../version-info'; import { $imports } from '../version-info';
import mockImportedComponents from '../../../test-util/mock-imported-components';
import { checkAccessibility } from '../../../test-util/accessibility'; import { checkAccessibility } from '../../../test-util/accessibility';
describe('VersionInfo', function () { describe('VersionInfo', function () {
...@@ -32,6 +33,7 @@ describe('VersionInfo', function () { ...@@ -32,6 +33,7 @@ describe('VersionInfo', function () {
fakeCopyToClipboard = { fakeCopyToClipboard = {
copyText: sinon.stub(), copyText: sinon.stub(),
}; };
$imports.$mock(mockImportedComponents());
$imports.$mock({ $imports.$mock({
'../util/copy-to-clipboard': fakeCopyToClipboard, '../util/copy-to-clipboard': fakeCopyToClipboard,
}); });
...@@ -65,7 +67,7 @@ describe('VersionInfo', function () { ...@@ -65,7 +67,7 @@ describe('VersionInfo', function () {
it('copies version info to clipboard when copy button clicked', () => { it('copies version info to clipboard when copy button clicked', () => {
const wrapper = createComponent(); const wrapper = createComponent();
wrapper.find('button').simulate('click'); wrapper.find('Button').props().onClick();
assert.calledWith(fakeCopyToClipboard.copyText, 'fakeString'); assert.calledWith(fakeCopyToClipboard.copyText, 'fakeString');
}); });
...@@ -73,7 +75,7 @@ describe('VersionInfo', function () { ...@@ -73,7 +75,7 @@ describe('VersionInfo', function () {
it('confirms info copy when successful', () => { it('confirms info copy when successful', () => {
const wrapper = createComponent(); const wrapper = createComponent();
wrapper.find('button').simulate('click'); wrapper.find('Button').props().onClick();
assert.calledWith( assert.calledWith(
fakeToastMessenger.success, fakeToastMessenger.success,
...@@ -85,7 +87,7 @@ describe('VersionInfo', function () { ...@@ -85,7 +87,7 @@ describe('VersionInfo', function () {
fakeCopyToClipboard.copyText.throws(); fakeCopyToClipboard.copyText.throws();
const wrapper = createComponent(); const wrapper = createComponent();
wrapper.find('button').simulate('click'); wrapper.find('Button').props().onClick();
assert.calledWith( assert.calledWith(
fakeToastMessenger.error, fakeToastMessenger.error,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment