- Kibana Guide: other versions:
- What is Kibana?
- What’s new in 8.3
- Kibana concepts
- Quick start
- Set up
- Install Kibana
- Configure Kibana
- Alerting and action settings
- APM settings
- Banners settings
- Enterprise Search settings
- Fleet settings
- i18n settings
- Logging settings
- Logs settings
- Metrics settings
- Monitoring settings
- Reporting settings
- Search sessions settings
- Secure settings
- Security settings
- Spaces settings
- Task Manager settings
- Telemetry settings
- URL drilldown settings
- Start and stop Kibana
- Access Kibana
- Securing access to Kibana
- Add data
- Upgrade Kibana
- Configure security
- Configure reporting
- Configure logging
- Configure monitoring
- Command line tools
- Production considerations
- Discover
- Dashboard and visualizations
- Canvas
- Maps
- Build a map to compare metrics by country or region
- Track, visualize, and alert on assets in real time
- Map custom regions with reverse geocoding
- Heat map layer
- Tile layer
- Vector layer
- Plot big data
- Search geographic data
- Configure map settings
- Connect to Elastic Maps Service
- Import geospatial data
- Troubleshoot
- Reporting and sharing
- Machine learning
- Graph
- Alerting
- Observability
- APM
- Security
- Dev Tools
- Fleet
- Osquery
- Stack Monitoring
- Stack Management
- REST API
- Get features API
- Kibana spaces APIs
- Kibana role management APIs
- User session management APIs
- Saved objects APIs
- Data views API
- Index patterns APIs
- Alerting APIs
- Action and connector APIs
- Cases APIs
- Import and export dashboard APIs
- Logstash configuration management APIs
- Machine learning APIs
- Short URLs APIs
- Get Task Manager health
- Upgrade assistant APIs
- Kibana plugins
- Troubleshooting
- Accessibility
- Release notes
- Developer guide
Testing Kibana Plugins
editTesting Kibana Plugins
editWriting tests
editLearn about recommended testing approaches .
Mock Kibana Core services in tests
editCore services already provide mocks to simplify testing and make sure plugins always rely on valid public contracts:
my_plugin/server/plugin.test.ts
import { configServiceMock } from '@kbn/core/server/mocks'; const configService = configServiceMock.create(); configService.atPath.mockReturnValue(config$); … const plugin = new MyPlugin({ configService }, …);
Or if you need to get the whole core setup
or start
contracts:
my_plugin/server/plugin.test.ts
import { coreMock } from '@kbn/core/public/mocks'; const coreSetup = coreMock.createSetup(); coreSetup.uiSettings.get.mockImplementation((key: string) => { … }); … const plugin = new MyPlugin(coreSetup, ...);
Writing mocks for your plugin
editAlthough it isn’t mandatory, we strongly recommended you export your
plugin mocks as well, in order for dependent plugins to use them in
tests. Your plugin mocks should be exported from the root /server
and
/public
directories in your plugin:
my_plugin/(server|public)/mocks.ts
const createSetupContractMock = () => { const startContract: jest.Mocked<MyPluginStartContract>= { isValid: jest.fn(), } // here we already type check as TS infers to the correct type declared above startContract.isValid.mockReturnValue(true); return startContract; } export const myPluginMocks = { createSetup: createSetupContractMock, createStart: … }
Plugin mocks should consist of mocks for public APIs only:
setup
, start
& stop
contracts. Mocks aren’t necessary for pure functions as
other plugins can call the original implementation in tests.