-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
☁️ Nx Cloud ReportCI 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 targetSent with 💌 from NxCloud. |
@@ -9,6 +9,15 @@ import { | |||
describe('SdkTrainingComponent', () => { | |||
let component: SdkTrainingComponent; | |||
let fixture: ComponentFixture<SdkTrainingComponent>; | |||
global.fetch = jest.fn(() => Promise.resolve({ |
There was a problem hiding this comment.
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)
apps/showcase/testing/setup-jest.ts
Outdated
@@ -1 +1,30 @@ | |||
import 'jest-preset-angular/setup-jest'; | |||
|
|||
jest.mock('@webcontainer/api', |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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';
e38d734
to
43920a1
Compare
43920a1
to
1470330
Compare
Proposed change
Related issues
- No issue associated -