Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest and Storybook fixes #116132

Merged
merged 11 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion x-pack/plugins/apm/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ module.exports = {
preset: '@kbn/test',
rootDir: path.resolve(__dirname, '../../..'),
roots: ['<rootDir>/x-pack/plugins/apm'],
setupFiles: ['<rootDir>/x-pack/plugins/apm/.storybook/jest_setup.js'],
setupFiles: [
'<rootDir>/x-pack/plugins/apm/jest_setup.js',
'<rootDir>/x-pack/plugins/apm/.storybook/jest_setup.js',
],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/x-pack/plugins/apm',
coverageReporters: ['text', 'html'],
collectCoverageFrom: [
Expand Down
14 changes: 14 additions & 0 deletions x-pack/plugins/apm/jest_setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

/* global jest */

// When a `console.error` is encountered, throw the error to make the test fail.
// This effectively treats logged errors during the test run as failures.
jest.spyOn(console, 'error').mockImplementation((message) => {
throw new Error(message);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ import { AlertParams, ErrorCountAlertTrigger } from '.';
import { CoreStart } from '../../../../../../../src/core/public';
import { createKibanaReactContext } from '../../../../../../../src/plugins/kibana_react/public';
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
import { createCallApmApi } from '../../../services/rest/createCallApmApi';

import { AlertMetadata } from '../helper';

const KibanaReactContext = createKibanaReactContext({
const coreMock = {
http: { get: async () => ({}) },
notifications: { toasts: { add: () => {} } },
} as unknown as Partial<CoreStart>);
uiSettings: { get: () => {} },
} as unknown as CoreStart;

const KibanaReactContext = createKibanaReactContext(coreMock);

interface Args {
alertParams: AlertParams;
Expand All @@ -27,6 +33,8 @@ const stories: Meta<{}> = {
component: ErrorCountAlertTrigger,
decorators: [
(StoryComponent) => {
createCallApmApi(coreMock);

return (
<KibanaReactContext.Provider>
<div style={{ width: 400 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
* 2.0.
*/

import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import React from 'react';
import * as stories from './error_count_alert_trigger.stories';
import { composeStories } from '@storybook/testing-react';

const { CreatingInApmFromService } = composeStories(stories);

describe('ErrorCountAlertTrigger', () => {
it('renders', () => {
expect(() => render(<CreatingInApmFromService />)).not.toThrowError();
it('renders', async () => {
render(<CreatingInApmFromService />);

expect(await screen.findByText('Service')).toBeInTheDocument();
});
});

This file was deleted.

Loading