mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-31 01:36:11 +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 '..';
|
import Dimensions from '..';
|
||||||
|
|
||||||
describe('apis/Dimensions', () => {
|
describe('apis/Dimensions', () => {
|
||||||
|
test('get', () => {
|
||||||
|
expect(Dimensions.get('screen')).toMatchSnapshot();
|
||||||
|
expect(Dimensions.get('window')).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('set', () => {
|
||||||
|
expect(() => Dimensions.set({})).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
test('addEventListener', () => {
|
test('addEventListener', () => {
|
||||||
const handler = jest.fn();
|
const handler = jest.fn();
|
||||||
Dimensions.addEventListener('change', handler);
|
Dimensions.addEventListener('change', handler);
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ export default class Dimensions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dimensions._update();
|
||||||
|
|
||||||
if (canUseDOM) {
|
if (canUseDOM) {
|
||||||
Dimensions._update();
|
|
||||||
window.addEventListener('resize', debounce(Dimensions._update, 16), false);
|
window.addEventListener('resize', debounce(Dimensions._update, 16), false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user