From 8d80885f5d95b48f17b3e5d352de4fb42972fd01 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 1 Aug 2017 11:23:02 -0700 Subject: [PATCH] [fix] Dimensions.get when called on the server --- .../__snapshots__/index-test.js.snap | 19 +++++++++++++++++++ src/apis/Dimensions/__tests__/index-test.js | 9 +++++++++ src/apis/Dimensions/index.js | 3 ++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/apis/Dimensions/__tests__/__snapshots__/index-test.js.snap diff --git a/src/apis/Dimensions/__tests__/__snapshots__/index-test.js.snap b/src/apis/Dimensions/__tests__/__snapshots__/index-test.js.snap new file mode 100644 index 00000000..0f9539f3 --- /dev/null +++ b/src/apis/Dimensions/__tests__/__snapshots__/index-test.js.snap @@ -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, +} +`; diff --git a/src/apis/Dimensions/__tests__/index-test.js b/src/apis/Dimensions/__tests__/index-test.js index a687ed14..c068e81a 100644 --- a/src/apis/Dimensions/__tests__/index-test.js +++ b/src/apis/Dimensions/__tests__/index-test.js @@ -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); diff --git a/src/apis/Dimensions/index.js b/src/apis/Dimensions/index.js index 5b7489ce..eab513b4 100644 --- a/src/apis/Dimensions/index.js +++ b/src/apis/Dimensions/index.js @@ -78,7 +78,8 @@ export default class Dimensions { } } +Dimensions._update(); + if (canUseDOM) { - Dimensions._update(); window.addEventListener('resize', debounce(Dimensions._update, 16), false); }