[fix] Dimensions.get when called on the server

This commit is contained in:
Nicolas Gallagher
2017-08-01 11:23:02 -07:00
parent 3ca4becc41
commit 8d80885f5d
3 changed files with 30 additions and 1 deletions
@@ -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);
+2 -1
View File
@@ -78,7 +78,8 @@ export default class Dimensions {
}
}
Dimensions._update();
if (canUseDOM) {
Dimensions._update();
window.addEventListener('resize', debounce(Dimensions._update, 16), false);
}