From db4ed55d9d380ff9851cad327a799d86c059202b Mon Sep 17 00:00:00 2001 From: Karan Shah Date: Tue, 8 Feb 2022 10:03:15 +0000 Subject: [PATCH] Error test now passes Signed-off-by: Karan Shah --- .../EntityAirbrakeWidget.test.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx b/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx index 5d3787b875..2415aa1bdf 100644 --- a/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx +++ b/plugins/airbrake/src/components/EntityAirbrakeWidget/EntityAirbrakeWidget.test.tsx @@ -17,7 +17,11 @@ import React from 'react'; import { EntityAirbrakeWidget } from './EntityAirbrakeWidget'; import exampleData from '../../api/mock/airbrake-groups-api-mock.json'; -import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; +import { + MockErrorApi, + renderInTestApp, + TestApiProvider, +} from '@backstage/test-utils'; import { createEntity } from '../../api/mock/mock-entity'; import { airbrakeApiRef, @@ -25,6 +29,7 @@ import { ProductionAirbrakeApi, } from '../../api'; import nock from 'nock'; +import { errorApiRef } from '@backstage/core-plugin-api'; describe('EntityAirbrakeContent', () => { it('renders all errors sent from Airbrake', async () => { @@ -57,18 +62,26 @@ describe('EntityAirbrakeContent', () => { .get('/api/v4/projects/123/groups?key=fakeApiKey') .reply(500); expect(scope.isDone()).toBe(false); + const mockErrorApi = new MockErrorApi({ collect: true }); const table = await renderInTestApp( , ); await expect( - table.findByText('*there was an issue communicating with Airbrake*'), + table.findByText(/.*there was an issue communicating with Airbrake.*/), ).resolves.toBeInTheDocument(); + expect(mockErrorApi.getErrors().length).toBe(1); + expect(mockErrorApi.getErrors()[0].error.message).toStrictEqual( + 'Failed fetching Airbrake groups', + ); expect(scope.isDone()).toBe(true); }); });