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

fix: mock webcontainer api and xterm for unit test #2545

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

cpaulve-1A
Copy link
Contributor

Proposed change

Related issues

- No issue associated -

@cpaulve-1A cpaulve-1A requested a review from a team as a code owner December 2, 2024 17:24
Copy link

nx-cloud bot commented Dec 2, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 1470330. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@github-actions github-actions bot added bug Something isn't working project:@o3r/showcase labels Dec 2, 2024
@@ -9,6 +9,15 @@ import {
describe('SdkTrainingComponent', () => {
let component: SdkTrainingComponent;
let fixture: ComponentFixture<SdkTrainingComponent>;
global.fetch = jest.fn(() => Promise.resolve({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe cleaner to be set in the beforeEach to renew the mock before each test.
Or, if the single mock is done on purpose, maybe moving it outside of the describe as it is affecting globally.

(same comment for the other tests)

@@ -1 +1,30 @@
import 'jest-preset-angular/setup-jest';

jest.mock('@webcontainer/api',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe more readable to move the both mocks on external testing/mocks/webcontainer-api.ts and testing/mocks/xterm-xtern.ts that you can import in this file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking:

// in webcontainer-api.mock.ts

class WebContainerApiMock {
  public static boot = jest.fn(() => Promise.resolve({
    on: jest.fn(() => jest.fn())
  }));
}
jest.mock('@webcontainer/api',
  () => ({
    WebContainer: WebContainerApiMock
  }), {
    virtual: true
  }
);

and in this file just:

import './mocks/webcontainer-api.mock';

@cpaulve-1A cpaulve-1A force-pushed the fix/unit-test branch 2 times, most recently from e38d734 to 43920a1 Compare December 3, 2024 14:31
@cpaulve-1A cpaulve-1A merged commit 71cdb74 into feat/otter-training Dec 4, 2024
2 checks passed
@cpaulve-1A cpaulve-1A deleted the fix/unit-test branch December 4, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working project:@o3r/showcase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants