mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-24 23:25:40 +00:00
[fix] Dimensions.get when called on the server
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`apis/Dimensions get 1`] = `
|
||||
Object {
|
||||
"fontScale": 1,
|
||||
"height": 0,
|
||||
"scale": 1,
|
||||
"width": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`apis/Dimensions get 2`] = `
|
||||
Object {
|
||||
"fontScale": 1,
|
||||
"height": 768,
|
||||
"scale": 1,
|
||||
"width": 1024,
|
||||
}
|
||||
`;
|
||||
@@ -3,6 +3,15 @@
|
||||
import Dimensions from '..';
|
||||
|
||||
describe('apis/Dimensions', () => {
|
||||
test('get', () => {
|
||||
expect(Dimensions.get('screen')).toMatchSnapshot();
|
||||
expect(Dimensions.get('window')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('set', () => {
|
||||
expect(() => Dimensions.set({})).toThrow();
|
||||
});
|
||||
|
||||
test('addEventListener', () => {
|
||||
const handler = jest.fn();
|
||||
Dimensions.addEventListener('change', handler);
|
||||
|
||||
@@ -78,7 +78,8 @@ export default class Dimensions {
|
||||
}
|
||||
}
|
||||
|
||||
Dimensions._update();
|
||||
|
||||
if (canUseDOM) {
|
||||
Dimensions._update();
|
||||
window.addEventListener('resize', debounce(Dimensions._update, 16), false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user