-
Notifications
You must be signed in to change notification settings - Fork 305
test(@toss/utils): wrote test code for getViewportSize
function
#259
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
Conversation
👷 Deploy request for slash-libraries pending review.Visit the deploys page to approve it
|
}); | ||
|
||
it('should return zero size when running on server', () => { | ||
delete (global as { window: unknown }).window; |
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'd like to test the server status, should I fill it out like this?
Is it better to mock the isServer
function itself
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.
@okinawaa
I think directly chaning the window
object in your tests could be risky. 😢
I'm not sure that your tests won't affect the other tests.
How about mocking it like this instead?
I try it based on this reference!
import { getViewportSize } from '.';
let windowSpy: jest.SpyInstance;
beforeEach(() => {
windowSpy = jest.spyOn(global, 'window', 'get');
});
afterEach(() => {
windowSpy.mockRestore();
});
describe('getViewportSize', () => {
it('should return viewport size', () => {
windowSpy.mockImplementation(() => ({
innerWidth: 1024,
innerHeight: 768,
}));
const expectedSize = { width: 1024, height: 768 };
const size = getViewportSize();
expect(size).toEqual(expectedSize);
});
it('should return zero size when running on server', () => {
windowSpy.mockImplementation(() => undefined);
const expectedSize = { width: 0, height: 0 };
const size = getViewportSize();
expect(size).toEqual(expectedSize);
});
});
@raon0211 is attempting to deploy a commit to the Toss Team on Vercel. A member of the Team first needs to authorize it. |
Overview
I wrote test code for getViewportSize function
PR Checklist