-1).toBeTruthy();
+ expect(styleElement.type).toEqual('style');
});
});
diff --git a/src/apis/AppState/__tests__/index-test.js b/src/apis/AppState/__tests__/index-test.js
index 54d51a30..a8559628 100644
--- a/src/apis/AppState/__tests__/index-test.js
+++ b/src/apis/AppState/__tests__/index-test.js
@@ -1,31 +1,30 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
import AppState from '..';
-import assert from 'assert';
-suite('apis/AppState', () => {
+describe('apis/AppState', () => {
const handler = () => {};
- teardown(() => {
+ afterEach(() => {
try { AppState.removeEventListener('change', handler); } catch (e) {}
});
- suite('addEventListener', () => {
+ describe('addEventListener', () => {
test('throws if the provided "eventType" is not supported', () => {
- assert.throws(() => AppState.addEventListener('foo', handler));
- assert.doesNotThrow(() => AppState.addEventListener('change', handler));
+ expect(() => AppState.addEventListener('foo', handler)).toThrow();
+ expect(() => AppState.addEventListener('change', handler)).not.toThrow();
});
});
- suite('removeEventListener', () => {
+ describe('removeEventListener', () => {
test('throws if the handler is not registered', () => {
- assert.throws(() => AppState.removeEventListener('change', handler));
+ expect(() => AppState.removeEventListener('change', handler)).toThrow();
});
test('throws if the provided "eventType" is not supported', () => {
AppState.addEventListener('change', handler);
- assert.throws(() => AppState.removeEventListener('foo', handler));
- assert.doesNotThrow(() => AppState.removeEventListener('change', handler));
+ expect(() => AppState.removeEventListener('foo', handler)).toThrow();
+ expect(() => AppState.removeEventListener('change', handler)).not.toThrow();
});
});
});
diff --git a/src/apis/AsyncStorage/__tests__/__snapshots__/index-test.js.snap b/src/apis/AsyncStorage/__tests__/__snapshots__/index-test.js.snap
new file mode 100644
index 00000000..7e521156
--- /dev/null
+++ b/src/apis/AsyncStorage/__tests__/__snapshots__/index-test.js.snap
@@ -0,0 +1,11 @@
+exports[`apis/AsyncStorage mergeLocalStorageItem should have same behavior as react-native 1`] = `
+Object {
+ "age": 31,
+ "name": "Chris",
+ "traits": Object {
+ "eyes": "blue",
+ "hair": "brown",
+ "shoe_size": 10,
+ },
+}
+`;
diff --git a/src/apis/AsyncStorage/__tests__/index-test.js b/src/apis/AsyncStorage/__tests__/index-test.js
index 7ea5b627..db6e2ab2 100644
--- a/src/apis/AsyncStorage/__tests__/index-test.js
+++ b/src/apis/AsyncStorage/__tests__/index-test.js
@@ -1,5 +1,4 @@
-/* eslint-env mocha */
-import assert from 'assert';
+/* eslint-env jasmine, jest */
import AsyncStorage from '..';
const waterfall = (fns, cb) => {
@@ -20,9 +19,21 @@ const waterfall = (fns, cb) => {
_waterfall();
};
-suite('apis/AsyncStorage', () => {
- suite('mergeLocalStorageItem', () => {
+const obj = {};
+const mockLocalStorage = {
+ getItem(key) {
+ return obj[key];
+ },
+ setItem(key, value) {
+ obj[key] = value;
+ }
+};
+const originalLocalStorage = window.localStorage;
+
+describe('apis/AsyncStorage', () => {
+ describe('mergeLocalStorageItem', () => {
test('should have same behavior as react-native', (done) => {
+ window.localStorage = mockLocalStorage;
// https://facebook.github.io/react-native/docs/asyncstorage.html
const UID123_object = {
name: 'Chris',
@@ -33,6 +44,7 @@ suite('apis/AsyncStorage', () => {
age: 31,
traits: { eyes: 'blue', shoe_size: 10 }
};
+
waterfall([
(cb) => {
AsyncStorage.setItem('UID123', JSON.stringify(UID123_object))
@@ -52,12 +64,9 @@ suite('apis/AsyncStorage', () => {
.catch(cb);
}
], (err, result) => {
- assert.equal(err, null);
- assert.deepEqual(result, {
- 'name': 'Chris', 'age': 31, 'traits': {
- 'shoe_size': 10, 'hair': 'brown', 'eyes': 'blue'
- }
- });
+ expect(err).toEqual(null);
+ expect(result).toMatchSnapshot();
+ window.localStorage = originalLocalStorage;
done();
});
});
diff --git a/src/apis/Dimensions/__tests__/index-test.js b/src/apis/Dimensions/__tests__/index-test.js
index 62b241eb..804dff93 100644
--- a/src/apis/Dimensions/__tests__/index-test.js
+++ b/src/apis/Dimensions/__tests__/index-test.js
@@ -1,5 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-suite('apis/Dimensions', () => {
+describe('apis/Dimensions', () => {
test.skip('NO TEST COVERAGE', () => {});
});
diff --git a/src/apis/I18nManager/__tests__/index-test.js b/src/apis/I18nManager/__tests__/index-test.js
index 631a87b9..0b3dd672 100644
--- a/src/apis/I18nManager/__tests__/index-test.js
+++ b/src/apis/I18nManager/__tests__/index-test.js
@@ -1,45 +1,44 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import I18nManager from '..';
-suite('apis/I18nManager', () => {
- suite('when RTL not enabled', () => {
- setup(() => {
+describe('apis/I18nManager', () => {
+ describe('when RTL not enabled', () => {
+ beforeEach(() => {
I18nManager.setPreferredLanguageRTL(false);
});
test('is "false" by default', () => {
- assert.equal(I18nManager.isRTL, false);
- assert.equal(document.documentElement.getAttribute('dir'), 'ltr');
+ expect(I18nManager.isRTL).toEqual(false);
+ expect(document.documentElement.getAttribute('dir')).toEqual('ltr');
});
test('is "true" when forced', () => {
I18nManager.forceRTL(true);
- assert.equal(I18nManager.isRTL, true);
- assert.equal(document.documentElement.getAttribute('dir'), 'rtl');
+ expect(I18nManager.isRTL).toEqual(true);
+ expect(document.documentElement.getAttribute('dir')).toEqual('rtl');
I18nManager.forceRTL(false);
});
});
- suite('when RTL is enabled', () => {
- setup(() => {
+ describe('when RTL is enabled', () => {
+ beforeEach(() => {
I18nManager.setPreferredLanguageRTL(true);
});
- teardown(() => {
+ afterEach(() => {
I18nManager.setPreferredLanguageRTL(false);
});
test('is "true" by default', () => {
- assert.equal(I18nManager.isRTL, true);
- assert.equal(document.documentElement.getAttribute('dir'), 'rtl');
+ expect(I18nManager.isRTL).toEqual(true);
+ expect(document.documentElement.getAttribute('dir')).toEqual('rtl');
});
test('is "false" when not allowed', () => {
I18nManager.allowRTL(false);
- assert.equal(I18nManager.isRTL, false);
- assert.equal(document.documentElement.getAttribute('dir'), 'ltr');
+ expect(I18nManager.isRTL).toEqual(false);
+ expect(document.documentElement.getAttribute('dir')).toEqual('ltr');
I18nManager.allowRTL(true);
});
});
diff --git a/src/apis/NetInfo/__tests__/index-test.js b/src/apis/NetInfo/__tests__/index-test.js
index 0ab0b941..0c5b53fc 100644
--- a/src/apis/NetInfo/__tests__/index-test.js
+++ b/src/apis/NetInfo/__tests__/index-test.js
@@ -1,32 +1,31 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import NetInfo from '..';
-suite('apis/NetInfo', () => {
- suite('isConnected', () => {
+describe('apis/NetInfo', () => {
+ describe('isConnected', () => {
const handler = () => {};
- teardown(() => {
+ afterEach(() => {
try { NetInfo.isConnected.removeEventListener('change', handler); } catch (e) {}
});
- suite('addEventListener', () => {
+ describe('addEventListener', () => {
test('throws if the provided "eventType" is not supported', () => {
- assert.throws(() => NetInfo.isConnected.addEventListener('foo', handler));
- assert.doesNotThrow(() => NetInfo.isConnected.addEventListener('change', handler));
+ expect(() => NetInfo.isConnected.addEventListener('foo', handler)).toThrow();
+ expect(() => NetInfo.isConnected.addEventListener('change', handler)).not.toThrow();
});
});
- suite('removeEventListener', () => {
+ describe('removeEventListener', () => {
test('throws if the handler is not registered', () => {
- assert.throws(() => NetInfo.isConnected.removeEventListener('change', handler));
+ expect(() => NetInfo.isConnected.removeEventListener('change', handler)).toThrow;
});
test('throws if the provided "eventType" is not supported', () => {
NetInfo.isConnected.addEventListener('change', handler);
- assert.throws(() => NetInfo.isConnected.removeEventListener('foo', handler));
- assert.doesNotThrow(() => NetInfo.isConnected.removeEventListener('change', handler));
+ expect(() => NetInfo.isConnected.removeEventListener('foo', handler)).toThrow;
+ expect(() => NetInfo.isConnected.removeEventListener('change', handler)).not.toThrow;
});
});
});
diff --git a/src/apis/PixelRatio/__tests__/index-test.js b/src/apis/PixelRatio/__tests__/index-test.js
index 5ee4655a..a3f42d1a 100644
--- a/src/apis/PixelRatio/__tests__/index-test.js
+++ b/src/apis/PixelRatio/__tests__/index-test.js
@@ -1,5 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-suite('apis/PixelRatio', () => {
+describe('apis/PixelRatio', () => {
test.skip('NO TEST COVERAGE', () => {});
});
diff --git a/src/apis/StyleSheet/__tests__/__snapshots__/expandStyle-test.js.snap b/src/apis/StyleSheet/__tests__/__snapshots__/expandStyle-test.js.snap
new file mode 100644
index 00000000..641fe59f
--- /dev/null
+++ b/src/apis/StyleSheet/__tests__/__snapshots__/expandStyle-test.js.snap
@@ -0,0 +1,18 @@
+exports[`apis/StyleSheet/expandStyle shortform -> longform 1`] = `
+Object {
+ "borderBottomColor": "white",
+ "borderBottomStyle": "solid",
+ "borderBottomWidth": "1px",
+ "borderLeftStyle": "solid",
+ "borderLeftWidth": "0px",
+ "borderRightStyle": "solid",
+ "borderRightWidth": "0px",
+ "borderTopStyle": "solid",
+ "borderTopWidth": "0px",
+ "boxSizing": "border-box",
+ "marginBottom": "25px",
+ "marginLeft": "10px",
+ "marginRight": "10px",
+ "marginTop": "50px",
+}
+`;
diff --git a/src/apis/StyleSheet/__tests__/__snapshots__/i18nStyle-test.js.snap b/src/apis/StyleSheet/__tests__/__snapshots__/i18nStyle-test.js.snap
new file mode 100644
index 00000000..52be129b
--- /dev/null
+++ b/src/apis/StyleSheet/__tests__/__snapshots__/i18nStyle-test.js.snap
@@ -0,0 +1,107 @@
+exports[`apis/StyleSheet/i18nStyle LTR mode does not auto-flip 1`] = `
+Object {
+ "borderBottomLeftRadius": 20,
+ "borderBottomRightRadius": "2rem",
+ "borderLeftColor": "red",
+ "borderLeftStyle": "solid",
+ "borderLeftWidth": 5,
+ "borderRightColor": "blue",
+ "borderRightStyle": "dotted",
+ "borderRightWidth": 6,
+ "borderTopLeftRadius": 10,
+ "borderTopRightRadius": "1rem",
+ "left": 1,
+ "marginLeft": 7,
+ "marginRight": 8,
+ "paddingLeft": 9,
+ "paddingRight": 10,
+ "right": 2,
+ "textAlign": "left",
+ "textShadowOffset": Object {
+ "height": 10,
+ "width": "1rem",
+ },
+ "writingDirection": "ltr",
+}
+`;
+
+exports[`apis/StyleSheet/i18nStyle LTR mode normalizes properties 1`] = `
+Object {
+ "borderBottomLeftRadius": 20,
+ "borderBottomRightRadius": "2rem",
+ "borderLeftColor": "red",
+ "borderLeftStyle": "solid",
+ "borderLeftWidth": 5,
+ "borderRightColor": "blue",
+ "borderRightStyle": "dotted",
+ "borderRightWidth": 6,
+ "borderTopLeftRadius": 10,
+ "borderTopRightRadius": "1rem",
+ "left": 1,
+ "marginLeft": 7,
+ "marginRight": 8,
+ "paddingLeft": 9,
+ "paddingRight": 10,
+ "right": 2,
+ "textAlign": "left",
+ "textShadowOffset": Object {
+ "height": 10,
+ "width": "1rem",
+ },
+ "writingDirection": "ltr",
+}
+`;
+
+exports[`apis/StyleSheet/i18nStyle RTL mode does auto-flip 1`] = `
+Object {
+ "borderBottomLeftRadius": "2rem",
+ "borderBottomRightRadius": 20,
+ "borderLeftColor": "blue",
+ "borderLeftStyle": "dotted",
+ "borderLeftWidth": 6,
+ "borderRightColor": "red",
+ "borderRightStyle": "solid",
+ "borderRightWidth": 5,
+ "borderTopLeftRadius": "1rem",
+ "borderTopRightRadius": 10,
+ "left": 2,
+ "marginLeft": 8,
+ "marginRight": 7,
+ "paddingLeft": 10,
+ "paddingRight": 9,
+ "right": 1,
+ "textAlign": "right",
+ "textShadowOffset": Object {
+ "height": 10,
+ "width": "-1rem",
+ },
+ "writingDirection": "rtl",
+}
+`;
+
+exports[`apis/StyleSheet/i18nStyle RTL mode normalizes properties 1`] = `
+Object {
+ "borderBottomLeftRadius": 20,
+ "borderBottomRightRadius": "2rem",
+ "borderLeftColor": "red",
+ "borderLeftStyle": "solid",
+ "borderLeftWidth": 5,
+ "borderRightColor": "blue",
+ "borderRightStyle": "dotted",
+ "borderRightWidth": 6,
+ "borderTopLeftRadius": 10,
+ "borderTopRightRadius": "1rem",
+ "left": 1,
+ "marginLeft": 7,
+ "marginRight": 8,
+ "paddingLeft": 9,
+ "paddingRight": 10,
+ "right": 2,
+ "textAlign": "left",
+ "textShadowOffset": Object {
+ "height": 10,
+ "width": "-1rem",
+ },
+ "writingDirection": "ltr",
+}
+`;
diff --git a/src/apis/StyleSheet/__tests__/__snapshots__/index-test.js.snap b/src/apis/StyleSheet/__tests__/__snapshots__/index-test.js.snap
new file mode 100644
index 00000000..35bd0b8a
--- /dev/null
+++ b/src/apis/StyleSheet/__tests__/__snapshots__/index-test.js.snap
@@ -0,0 +1,10 @@
+exports[`apis/StyleSheet resolve 1`] = `
+Object {
+ "className": "test __style_df __style_pebn",
+ "style": Object {
+ "display": null,
+ "opacity": 1,
+ "pointerEvents": null,
+ },
+}
+`;
diff --git a/src/apis/StyleSheet/__tests__/createReactStyleObject-test.js b/src/apis/StyleSheet/__tests__/createReactStyleObject-test.js
index 10b66ce4..8769545c 100644
--- a/src/apis/StyleSheet/__tests__/createReactStyleObject-test.js
+++ b/src/apis/StyleSheet/__tests__/createReactStyleObject-test.js
@@ -1,13 +1,12 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import createReactStyleObject from '../createReactStyleObject';
-suite('apis/StyleSheet/createReactStyleObject', () => {
+describe('apis/StyleSheet/createReactStyleObject', () => {
test('converts ReactNative style to ReactDOM style', () => {
const reactNativeStyle = { display: 'flex', marginVertical: 0, opacity: 0 };
const expectedStyle = { display: 'flex', marginTop: '0px', marginBottom: '0px', opacity: 0 };
- assert.deepEqual(createReactStyleObject(reactNativeStyle), expectedStyle);
+ expect(createReactStyleObject(reactNativeStyle)).toEqual(expectedStyle);
});
});
diff --git a/src/apis/StyleSheet/__tests__/expandStyle-test.js b/src/apis/StyleSheet/__tests__/expandStyle-test.js
index 77628b67..2b4a37ff 100644
--- a/src/apis/StyleSheet/__tests__/expandStyle-test.js
+++ b/src/apis/StyleSheet/__tests__/expandStyle-test.js
@@ -1,11 +1,10 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import expandStyle from '../expandStyle';
-suite('apis/StyleSheet/expandStyle', () => {
+describe('apis/StyleSheet/expandStyle', () => {
test('shortform -> longform', () => {
- const initial = {
+ const style = {
borderStyle: 'solid',
boxSizing: 'border-box',
borderBottomColor: 'white',
@@ -16,24 +15,7 @@ suite('apis/StyleSheet/expandStyle', () => {
margin: 10
};
- const expected = {
- borderBottomStyle: 'solid',
- borderLeftStyle: 'solid',
- borderRightStyle: 'solid',
- boxSizing: 'border-box',
- borderBottomColor: 'white',
- borderTopStyle: 'solid',
- borderTopWidth: '0px',
- borderLeftWidth: '0px',
- borderRightWidth: '0px',
- borderBottomWidth: '1px',
- marginTop: '50px',
- marginBottom: '25px',
- marginLeft: '10px',
- marginRight: '10px'
- };
-
- assert.deepEqual(expandStyle(initial), expected);
+ expect(expandStyle(style)).toMatchSnapshot();
});
test('textAlignVertical', () => {
@@ -45,7 +27,7 @@ suite('apis/StyleSheet/expandStyle', () => {
verticalAlign: 'middle'
};
- assert.deepEqual(expandStyle(initial), expected);
+ expect(expandStyle(initial)).toEqual(expected);
});
test('flex', () => {
@@ -61,6 +43,6 @@ suite('apis/StyleSheet/expandStyle', () => {
flexBasis: 'auto'
};
- assert.deepEqual(expandStyle(initial), expected);
+ expect(expandStyle(initial)).toEqual(expected);
});
});
diff --git a/src/apis/StyleSheet/__tests__/i18nStyle-test.js b/src/apis/StyleSheet/__tests__/i18nStyle-test.js
index 7ee84c15..5350f84d 100644
--- a/src/apis/StyleSheet/__tests__/i18nStyle-test.js
+++ b/src/apis/StyleSheet/__tests__/i18nStyle-test.js
@@ -1,10 +1,9 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import I18nManager from '../../I18nManager';
import i18nStyle from '../i18nStyle';
-const initial = {
+const style = {
borderLeftColor: 'red',
borderRightColor: 'blue',
borderTopLeftRadius: 10,
@@ -26,66 +25,44 @@ const initial = {
writingDirection: 'ltr'
};
-const initialNoI18n = Object.keys(initial).reduce((acc, prop) => {
+const styleNoI18n = Object.keys(style).reduce((acc, prop) => {
const newProp = `${prop}$noI18n`;
- acc[newProp] = initial[prop];
+ acc[newProp] = style[prop];
return acc;
}, {});
-const expected = {
- borderLeftColor: 'blue',
- borderRightColor: 'red',
- borderTopLeftRadius: '1rem',
- borderTopRightRadius: 10,
- borderBottomLeftRadius: '2rem',
- borderBottomRightRadius: 20,
- borderLeftStyle: 'dotted',
- borderRightStyle: 'solid',
- borderLeftWidth: 6,
- borderRightWidth: 5,
- left: 2,
- marginLeft: 8,
- marginRight: 7,
- paddingLeft: 10,
- paddingRight: 9,
- right: 1,
- textAlign: 'right',
- textShadowOffset: { width: '-1rem', height: 10 },
- writingDirection: 'rtl'
-};
-
-suite('apis/StyleSheet/i18nStyle', () => {
- suite('LTR mode', () => {
- setup(() => {
+describe('apis/StyleSheet/i18nStyle', () => {
+ describe('LTR mode', () => {
+ beforeEach(() => {
I18nManager.allowRTL(false);
});
- teardown(() => {
+ afterEach(() => {
I18nManager.allowRTL(true);
});
test('does not auto-flip', () => {
- assert.deepEqual(i18nStyle(initial), initial);
+ expect(i18nStyle(style)).toMatchSnapshot();
});
test('normalizes properties', () => {
- assert.deepEqual(i18nStyle(initialNoI18n), initial);
+ expect(i18nStyle(styleNoI18n)).toMatchSnapshot();
});
});
- suite('RTL mode', () => {
- setup(() => {
+ describe('RTL mode', () => {
+ beforeEach(() => {
I18nManager.forceRTL(true);
});
- teardown(() => {
+ afterEach(() => {
I18nManager.forceRTL(false);
});
test('does auto-flip', () => {
- assert.deepEqual(i18nStyle(initial), expected);
+ expect(i18nStyle(style)).toMatchSnapshot();
});
test('normalizes properties', () => {
- assert.deepEqual(i18nStyle(initialNoI18n), initial);
+ expect(i18nStyle(styleNoI18n)).toMatchSnapshot();
});
});
});
diff --git a/src/apis/StyleSheet/__tests__/index-test.js b/src/apis/StyleSheet/__tests__/index-test.js
index 7f89d641..9c714c37 100644
--- a/src/apis/StyleSheet/__tests__/index-test.js
+++ b/src/apis/StyleSheet/__tests__/index-test.js
@@ -1,71 +1,54 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import { getDefaultStyleSheet } from '../css';
import isPlainObject from 'lodash/isPlainObject';
import StyleSheet from '..';
-suite('apis/StyleSheet', () => {
- setup(() => {
+describe('apis/StyleSheet', () => {
+ beforeEach(() => {
StyleSheet._reset();
});
test('absoluteFill', () => {
- assert(Number.isInteger(StyleSheet.absoluteFill) === true);
+ expect(Number.isInteger(StyleSheet.absoluteFill) === true).toBeTruthy();
});
test('absoluteFillObject', () => {
- assert.ok(isPlainObject(StyleSheet.absoluteFillObject) === true);
+ expect(isPlainObject(StyleSheet.absoluteFillObject) === true).toBeTruthy();
});
- suite('create', () => {
+ describe('create', () => {
test('replaces styles with numbers', () => {
const style = StyleSheet.create({ root: { opacity: 1 } });
- assert(Number.isInteger(style.root) === true);
+ expect(Number.isInteger(style.root) === true).toBeTruthy();
});
test('renders a style sheet in the browser', () => {
StyleSheet.create({ root: { color: 'red' } });
- assert.equal(
- document.getElementById('__react-native-style').textContent,
- getDefaultStyleSheet()
- );
+ expect(document.getElementById('__react-native-style').textContent).toEqual(getDefaultStyleSheet());
});
});
test('flatten', () => {
- assert(typeof StyleSheet.flatten === 'function');
+ expect(typeof StyleSheet.flatten === 'function').toBeTruthy();
});
test('hairlineWidth', () => {
- assert(Number.isInteger(StyleSheet.hairlineWidth) === true);
+ expect(Number.isInteger(StyleSheet.hairlineWidth) === true).toBeTruthy();
});
test('render', () => {
- assert.equal(
- StyleSheet.render().props.dangerouslySetInnerHTML.__html,
- getDefaultStyleSheet()
- );
+ expect(StyleSheet.render().props.dangerouslySetInnerHTML.__html).toEqual(getDefaultStyleSheet());
});
test('resolve', () => {
- assert.deepEqual(
- StyleSheet.resolve({
- className: 'test',
- style: {
- display: 'flex',
- opacity: 1,
- pointerEvents: 'box-none'
- }
- }),
- {
- className: 'test __style_df __style_pebn',
- style: {
- display: null,
- opacity: 1,
- pointerEvents: null
- }
+ expect(StyleSheet.resolve({
+ className: 'test',
+ style: {
+ display: 'flex',
+ opacity: 1,
+ pointerEvents: 'box-none'
}
- );
+ })).toMatchSnapshot();
});
});
diff --git a/src/apis/StyleSheet/__tests__/normalizeValue-test.js b/src/apis/StyleSheet/__tests__/normalizeValue-test.js
index c42168e0..b632cfcc 100644
--- a/src/apis/StyleSheet/__tests__/normalizeValue-test.js
+++ b/src/apis/StyleSheet/__tests__/normalizeValue-test.js
@@ -1,14 +1,13 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import normalizeValue from '../normalizeValue';
-suite('apis/StyleSheet/normalizeValue', () => {
+describe('apis/StyleSheet/normalizeValue', () => {
test('normalizes property values requiring units', () => {
- assert.deepEqual(normalizeValue('margin', 0), '0px');
+ expect(normalizeValue('margin', 0)).toEqual('0px');
});
test('ignores unitless property values', () => {
- assert.deepEqual(normalizeValue('flexGrow', 1), 1);
- assert.deepEqual(normalizeValue('scale', 2), 2);
+ expect(normalizeValue('flexGrow', 1)).toEqual(1);
+ expect(normalizeValue('scale', 2)).toEqual(2);
});
});
diff --git a/src/apis/StyleSheet/__tests__/processTextShadow-test.js b/src/apis/StyleSheet/__tests__/processTextShadow-test.js
index 3d016f75..8784e1da 100644
--- a/src/apis/StyleSheet/__tests__/processTextShadow-test.js
+++ b/src/apis/StyleSheet/__tests__/processTextShadow-test.js
@@ -1,9 +1,8 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import processTextShadow from '../processTextShadow';
-suite('apis/StyleSheet/processTextShadow', () => {
+describe('apis/StyleSheet/processTextShadow', () => {
test('textShadowOffset', () => {
const style = {
textShadowColor: 'red',
@@ -11,14 +10,11 @@ suite('apis/StyleSheet/processTextShadow', () => {
textShadowRadius: 5
};
- assert.deepEqual(
- processTextShadow(style),
- {
- textShadow: '2px 2px 5px red',
- textShadowColor: null,
- textShadowOffset: null,
- textShadowRadius: null
- }
- );
+ expect(processTextShadow(style)).toEqual({
+ textShadow: '2px 2px 5px red',
+ textShadowColor: null,
+ textShadowOffset: null,
+ textShadowRadius: null
+ });
});
});
diff --git a/src/apis/StyleSheet/__tests__/processTransform-test.js b/src/apis/StyleSheet/__tests__/processTransform-test.js
index fe7fa161..105f5f5a 100644
--- a/src/apis/StyleSheet/__tests__/processTransform-test.js
+++ b/src/apis/StyleSheet/__tests__/processTransform-test.js
@@ -1,9 +1,8 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import processTransform from '../processTransform';
-suite('apis/StyleSheet/processTransform', () => {
+describe('apis/StyleSheet/processTransform', () => {
test('transform', () => {
const style = {
transform: [
@@ -13,10 +12,7 @@ suite('apis/StyleSheet/processTransform', () => {
]
};
- assert.deepEqual(
- processTransform(style),
- { transform: 'scaleX(20) translateX(20px) rotate(20deg)' }
- );
+ expect(processTransform(style)).toEqual({ transform: 'scaleX(20) translateX(20px) rotate(20deg)' });
});
test('transformMatrix', () => {
@@ -24,12 +20,9 @@ suite('apis/StyleSheet/processTransform', () => {
transformMatrix: [ 1, 2, 3, 4, 5, 6 ]
};
- assert.deepEqual(
- processTransform(style),
- {
- transform: 'matrix3d(1,2,3,4,5,6)',
- transformMatrix: null
- }
- );
+ expect(processTransform(style)).toEqual({
+ transform: 'matrix3d(1,2,3,4,5,6)',
+ transformMatrix: null
+ });
});
});
diff --git a/src/apis/StyleSheet/__tests__/processVendorPrefixes-test.js b/src/apis/StyleSheet/__tests__/processVendorPrefixes-test.js
index 1a04c666..db52d4da 100644
--- a/src/apis/StyleSheet/__tests__/processVendorPrefixes-test.js
+++ b/src/apis/StyleSheet/__tests__/processVendorPrefixes-test.js
@@ -1,17 +1,13 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import processVendorPrefixes from '../processVendorPrefixes';
-suite('apis/StyleSheet/processVendorPrefixes', () => {
+describe('apis/StyleSheet/processVendorPrefixes', () => {
test('handles array values', () => {
const style = {
display: [ '-webkit-flex', 'flex' ]
};
- assert.deepEqual(
- processVendorPrefixes(style),
- { display: 'flex' }
- );
+ expect(processVendorPrefixes(style)).toEqual({ display: 'flex' });
});
});
diff --git a/src/apis/UIManager/__tests__/index-test.js b/src/apis/UIManager/__tests__/index-test.js
index 82e08efa..3b82e08b 100644
--- a/src/apis/UIManager/__tests__/index-test.js
+++ b/src/apis/UIManager/__tests__/index-test.js
@@ -1,6 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import UIManager from '..';
const createNode = (style = {}) => {
@@ -13,47 +12,52 @@ const createNode = (style = {}) => {
let defaultBodyMargin;
-suite('apis/UIManager', () => {
- setup(() => {
+describe('apis/UIManager', () => {
+ beforeEach(() => {
// remove default body margin so we can predict the measured offsets
defaultBodyMargin = document.body.style.margin;
document.body.style.margin = 0;
});
- teardown(() => {
+ afterEach(() => {
document.body.style.margin = defaultBodyMargin;
});
- suite('measure', () => {
+ describe('measure', () => {
test('provides correct layout to callback', () => {
const node = createNode({ height: '5000px', left: '100px', position: 'relative', top: '100px', width: '5000px' });
document.body.appendChild(node);
+ node.getBoundingClientRect = jest.fn(() => ({ width: 5000, height: 5000, top: 100, left: 100 }));
+
UIManager.measure(node, (x, y, width, height, pageX, pageY) => {
- assert.equal(x, 100);
- assert.equal(y, 100);
- assert.equal(width, 5000);
- assert.equal(height, 5000);
- assert.equal(pageX, 100);
- assert.equal(pageY, 100);
+ expect(x).toEqual(100);
+ expect(y).toEqual(100);
+ expect(width).toEqual(5000);
+ expect(height).toEqual(5000);
+ expect(pageX).toEqual(100);
+ expect(pageY).toEqual(100);
});
// test values account for scroll position
window.scrollTo(200, 200);
+ node.getBoundingClientRect = jest.fn(() => ({ width: 5000, height: 5000, top: -100, left: -100 }));
+ node.parentNode.getBoundingClientRect = jest.fn(() => ({ top: -200, left: -200 }));
+
UIManager.measure(node, (x, y, width, height, pageX, pageY) => {
- assert.equal(x, 100);
- assert.equal(y, 100);
- assert.equal(width, 5000);
- assert.equal(height, 5000);
- assert.equal(pageX, -100);
- assert.equal(pageY, -100);
+ expect(x).toEqual(100);
+ expect(y).toEqual(100);
+ expect(width).toEqual(5000);
+ expect(height).toEqual(5000);
+ expect(pageX).toEqual(-100);
+ expect(pageY).toEqual(-100);
});
document.body.removeChild(node);
});
});
- suite('measureLayout', () => {
+ describe('measureLayout', () => {
test('provides correct layout to onSuccess callback', () => {
const node = createNode({ height: '10px', width: '10px' });
const middle = createNode({ padding: '20px' });
@@ -62,18 +66,25 @@ suite('apis/UIManager', () => {
context.appendChild(middle);
document.body.appendChild(context);
+ node.getBoundingClientRect = jest.fn(() => ({
+ width: 10,
+ height: 10,
+ top: 40,
+ left: 40
+ }));
+
UIManager.measureLayout(node, context, () => {}, (x, y, width, height) => {
- assert.equal(x, 40);
- assert.equal(y, 40);
- assert.equal(width, 10);
- assert.equal(height, 10);
+ expect(x).toEqual(40);
+ expect(y).toEqual(40);
+ expect(width).toEqual(10);
+ expect(height).toEqual(10);
});
document.body.removeChild(context);
});
});
- suite('measureInWindow', () => {
+ describe('measureInWindow', () => {
test('provides correct layout to callback', () => {
const node = createNode({ height: '10px', width: '10px' });
const middle = createNode({ padding: '20px' });
@@ -82,18 +93,25 @@ suite('apis/UIManager', () => {
context.appendChild(middle);
document.body.appendChild(context);
+ node.getBoundingClientRect = jest.fn(() => ({
+ width: 10,
+ height: 10,
+ top: 40,
+ left: 40
+ }));
+
UIManager.measureInWindow(node, (x, y, width, height) => {
- assert.equal(x, 40);
- assert.equal(y, 40);
- assert.equal(width, 10);
- assert.equal(height, 10);
+ expect(x).toEqual(40);
+ expect(y).toEqual(40);
+ expect(width).toEqual(10);
+ expect(height).toEqual(10);
});
document.body.removeChild(context);
});
});
- suite('updateView', () => {
+ describe('updateView', () => {
const componentStub = {
_reactInternalInstance: {
_currentElement: { _owner: {} },
@@ -106,14 +124,14 @@ suite('apis/UIManager', () => {
node.className = 'existing';
const props = { className: 'extra' };
UIManager.updateView(node, props, componentStub);
- assert.equal(node.getAttribute('class'), 'existing extra');
+ expect(node.getAttribute('class')).toEqual('existing extra');
});
test('adds correct DOM styles to existing style', () => {
const node = createNode({ color: 'red' });
const props = { style: { marginVertical: 0, opacity: 0 } };
UIManager.updateView(node, props, componentStub);
- assert.equal(node.getAttribute('style'), 'color: red; margin-top: 0px; margin-bottom: 0px; opacity: 0;');
+ expect(node.getAttribute('style')).toEqual('color: red; margin-top: 0px; margin-bottom: 0px; opacity: 0;');
});
test('replaces input and textarea text', () => {
@@ -123,18 +141,18 @@ suite('apis/UIManager', () => {
const valueProp = { value: 'expected-value' };
UIManager.updateView(node, textProp);
- assert.equal(node.value, 'expected-text');
+ expect(node.value).toEqual('expected-text');
UIManager.updateView(node, valueProp);
- assert.equal(node.value, 'expected-value');
+ expect(node.value).toEqual('expected-value');
});
test('sets other attribute values', () => {
const node = createNode();
const props = { 'aria-level': '4', 'data-of-type': 'string' };
UIManager.updateView(node, props);
- assert.equal(node.getAttribute('aria-level'), '4');
- assert.equal(node.getAttribute('data-of-type'), 'string');
+ expect(node.getAttribute('aria-level')).toEqual('4');
+ expect(node.getAttribute('data-of-type')).toEqual('string');
});
});
});
diff --git a/src/components/ActivityIndicator/__tests__/index-test.js b/src/components/ActivityIndicator/__tests__/index-test.js
index cdaec69f..34aa66d7 100644
--- a/src/components/ActivityIndicator/__tests__/index-test.js
+++ b/src/components/ActivityIndicator/__tests__/index-test.js
@@ -1,5 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-suite('components/ActivityIndicator', () => {
+describe('components/ActivityIndicator', () => {
test.skip('NO TEST COVERAGE', () => {});
});
diff --git a/src/components/Image/__tests__/__snapshots__/index-test.js.snap b/src/components/Image/__tests__/__snapshots__/index-test.js.snap
new file mode 100644
index 00000000..ee82fe53
--- /dev/null
+++ b/src/components/Image/__tests__/__snapshots__/index-test.js.snap
@@ -0,0 +1,1149 @@
+exports[`components/Image prop "accessibilityLabel" 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "accessible" 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "children" 1`] = `
+
+

+
+
+`;
+
+exports[`components/Image prop "defaultSource" does not override "height" and "width" styles 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "defaultSource" sets "height" and "width" styles if missing 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "defaultSource" sets background image when value is a string 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "defaultSource" sets background image when value is an object 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "resizeMode" value "contain" 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "resizeMode" value "cover" 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "resizeMode" value "none" 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "resizeMode" value "stretch" 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "resizeMode" value "undefined" 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "style" correctly supports "resizeMode" property 1`] = `
+
+

+
+`;
+
+exports[`components/Image prop "testID" 1`] = `
+
+

+
+`;
+
+exports[`components/Image sets correct accessibility role" 1`] = `
+
+

+
+`;
diff --git a/src/components/Image/__tests__/index-test.js b/src/components/Image/__tests__/index-test.js
index cde80b6e..14ac071d 100644
--- a/src/components/Image/__tests__/index-test.js
+++ b/src/components/Image/__tests__/index-test.js
@@ -1,182 +1,94 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import Image from '../';
import React from 'react';
-import StyleSheet from '../../../apis/StyleSheet';
-import { mount, shallow } from 'enzyme';
+import renderer from 'react-test-renderer';
+
+jest.mock('react-dom');
+
+const originalImage = window.Image;
+
+describe('components/Image', () => {
+ beforeEach(() => {
+ window.Image = jest.fn(() => ({}));
+ });
+
+ afterEach(() => {
+ window.Image = originalImage;
+ });
-suite('components/Image', () => {
test('sets correct accessibility role"', () => {
- const image = shallow(
);
- assert.equal(image.prop('accessibilityRole'), 'img');
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "accessibilityLabel"', () => {
- const accessibilityLabel = 'accessibilityLabel';
- const image = shallow(
);
- assert.equal(image.prop('accessibilityLabel'), accessibilityLabel);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "accessible"', () => {
- const accessible = false;
- const image = shallow(
);
- assert.equal(image.prop('accessible'), accessible);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "children"', () => {
const children =
;
- const wrapper = shallow(
{children});
- assert.equal(wrapper.contains(children), true);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
- suite('prop "defaultSource"', () => {
+ describe('prop "defaultSource"', () => {
test('sets background image when value is an object', () => {
const defaultSource = { uri: 'https://google.com/favicon.ico' };
- const image = shallow(
);
- const style = StyleSheet.flatten(image.prop('style'));
- assert(style.backgroundImage.indexOf(defaultSource.uri) > -1);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('sets background image when value is a string', () => {
// emulate require-ed asset
const defaultSource = 'https://google.com/favicon.ico';
- const image = shallow(
);
- const backgroundImage = StyleSheet.flatten(image.prop('style')).backgroundImage;
- assert(backgroundImage.indexOf(defaultSource) > -1);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('sets "height" and "width" styles if missing', () => {
const defaultSource = { uri: 'https://google.com/favicon.ico', height: 10, width: 20 };
- const image = mount(
);
- const html = image.html();
- assert(html.indexOf('height: 10px') > -1);
- assert(html.indexOf('width: 20px') > -1);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('does not override "height" and "width" styles', () => {
const defaultSource = { uri: 'https://google.com/favicon.ico', height: 10, width: 20 };
- const image = mount(
);
- const html = image.html();
- assert(html.indexOf('height: 20px') > -1);
- assert(html.indexOf('width: 40px') > -1);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
});
- test('prop "onError"', function (done) {
- this.timeout(5000);
- const image = mount(
);
- function onError(e) {
- assert.ok(e.nativeEvent.error);
- image.unmount();
- done();
- }
- });
-
- test('prop "onLoad"', function (done) {
- this.timeout(5000);
- const image = mount(
);
- function onLoad(e) {
- assert.equal(e.nativeEvent.type, 'load');
- const hasBackgroundImage = (image.html()).indexOf('url("https://google.com/favicon.ico")') > -1;
- assert.equal(hasBackgroundImage, true);
- image.unmount();
- done();
- }
- });
-
- test('prop "onLoadEnd"', function (done) {
- this.timeout(5000);
- const image = mount(
);
- function onLoadEnd() {
- assert.ok(true);
- const hasBackgroundImage = (image.html()).indexOf('url("https://google.com/favicon.ico")') > -1;
- assert.equal(hasBackgroundImage, true);
- image.unmount();
- done();
- }
- });
-
- test('prop "onLoadStart"', function (done) {
- this.timeout(5000);
- mount(
);
- function onLoadStart() {
- assert.ok(true);
- done();
- }
- });
-
- suite('prop "resizeMode"', () => {
- const getBackgroundSize = (image) => StyleSheet.flatten(image.prop('style')).backgroundSize;
-
- test('value "contain"', () => {
- const image = shallow(
);
- assert.equal(getBackgroundSize(image), 'contain');
- });
-
- test('value "cover"', () => {
- const image = shallow(
);
- assert.equal(getBackgroundSize(image), 'cover');
- });
-
- test('value "none"', () => {
- const image = shallow(
);
- assert.equal(getBackgroundSize(image), 'auto');
- });
-
- test('value "stretch"', () => {
- const image = shallow(
);
- assert.equal(getBackgroundSize(image), '100% 100%');
- });
-
- test('no value', () => {
- const image = shallow(
);
- assert.equal(getBackgroundSize(image), 'cover');
+ describe('prop "resizeMode"', () => {
+ [
+ Image.resizeMode.contain,
+ Image.resizeMode.cover,
+ Image.resizeMode.none,
+ Image.resizeMode.stretch,
+ undefined
+ ].forEach((resizeMode) => {
+ test(`value "${resizeMode}"`, () => {
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
+ });
});
});
- suite('prop "source"', function () {
- this.timeout(5000);
-
- test('sets background image when value is an object', (done) => {
- const source = { uri: 'https://google.com/favicon.ico' };
- const image = mount(
);
- function onLoad(e) {
- const src = e.nativeEvent.target.src;
- assert.equal(src, source.uri);
- image.unmount();
- done();
- }
- });
-
- test('sets background image when value is a string', (done) => {
- // emulate require-ed asset
- const source = 'https://google.com/favicon.ico';
- const image = mount(
);
- function onLoad(e) {
- const src = e.nativeEvent.target.src;
- assert.equal(src, source);
- image.unmount();
- done();
- }
- });
- });
-
- suite('prop "style"', () => {
- test('converts "resizeMode" property', () => {
- const image = shallow(
);
- assert.equal(StyleSheet.flatten(image.prop('style')).backgroundSize, 'contain');
- });
-
- test('removes "resizeMode" property', () => {
- const image = shallow(
);
- assert.equal(StyleSheet.flatten(image.prop('style')).resizeMode, undefined);
+ describe('prop "style"', () => {
+ test('correctly supports "resizeMode" property', () => {
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
});
test('prop "testID"', () => {
- const testID = 'testID';
- const image = shallow(
);
- assert.equal(image.prop('testID'), testID);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
});
diff --git a/src/components/ListView/__tests__/index-test.js b/src/components/ListView/__tests__/index-test.js
index c6bedd39..84163662 100644
--- a/src/components/ListView/__tests__/index-test.js
+++ b/src/components/ListView/__tests__/index-test.js
@@ -1,5 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-suite('components/ListView', () => {
+describe('components/ListView', () => {
test('NO TEST COVERAGE');
});
diff --git a/src/components/ProgressBar/__tests__/index-test.js b/src/components/ProgressBar/__tests__/index-test.js
index 1df0bf09..b04239b1 100644
--- a/src/components/ProgressBar/__tests__/index-test.js
+++ b/src/components/ProgressBar/__tests__/index-test.js
@@ -1,20 +1,19 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import React from 'react';
import { shallow } from 'enzyme';
import ProgressBar from '..';
-suite('components/ProgressBar', () => {
- suite('progress', () => {
- test('value as percentage is set to "aria-valuenow"', () => {
+describe('components/ProgressBar', () => {
+ describe('progress', () => {
+ it('value as percentage is set to "aria-valuenow"', () => {
const component = shallow(
);
- assert(component.prop('aria-valuenow') === 50);
+ expect(component.prop('aria-valuenow') === 50).toBeTruthy();
});
- test('is ignored when "indeterminate" is "true"', () => {
+ it('is ignored when "indeterminate" is "true"', () => {
const component = shallow(
);
- assert(component.prop('aria-valuenow') === null);
+ expect(component.prop('aria-valuenow') === null).toBeTruthy();
});
});
});
diff --git a/src/components/ScrollView/__tests__/index-test.js b/src/components/ScrollView/__tests__/index-test.js
index 72be36e9..74240599 100644
--- a/src/components/ScrollView/__tests__/index-test.js
+++ b/src/components/ScrollView/__tests__/index-test.js
@@ -1,5 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-suite('components/ScrollView', () => {
+describe('components/ScrollView', () => {
test('NO TEST COVERAGE');
});
diff --git a/src/components/StaticContainer/__tests__/index-test.js b/src/components/StaticContainer/__tests__/index-test.js
index 2357404a..93a298e6 100644
--- a/src/components/StaticContainer/__tests__/index-test.js
+++ b/src/components/StaticContainer/__tests__/index-test.js
@@ -1,5 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-suite('components/StaticContainer', () => {
+describe('components/StaticContainer', () => {
test.skip('NO TEST COVERAGE', () => {});
});
diff --git a/src/components/StaticRenderer/__tests__/index-test.js b/src/components/StaticRenderer/__tests__/index-test.js
index da493c06..4ebb8957 100644
--- a/src/components/StaticRenderer/__tests__/index-test.js
+++ b/src/components/StaticRenderer/__tests__/index-test.js
@@ -1,5 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-suite('components/StaticRenderer', () => {
+describe('components/StaticRenderer', () => {
test.skip('NO TEST COVERAGE', () => {});
});
diff --git a/src/components/Switch/__tests__/__snapshots__/index-test.js.snap b/src/components/Switch/__tests__/__snapshots__/index-test.js.snap
new file mode 100644
index 00000000..63812540
--- /dev/null
+++ b/src/components/Switch/__tests__/__snapshots__/index-test.js.snap
@@ -0,0 +1,843 @@
+exports[`components/Switch disabled when "false" a default checkbox is rendered 1`] = `
+
+`;
+
+exports[`components/Switch disabled when "true" a disabled checkbox is rendered 1`] = `
+
+`;
+
+exports[`components/Switch value when "false" an unchecked checkbox is rendered 1`] = `
+
+`;
+
+exports[`components/Switch value when "true" a checked checkbox is rendered 1`] = `
+
+`;
diff --git a/src/components/Switch/__tests__/index-test.js b/src/components/Switch/__tests__/index-test.js
index baf3971b..d69d522d 100644
--- a/src/components/Switch/__tests__/index-test.js
+++ b/src/components/Switch/__tests__/index-test.js
@@ -1,46 +1,50 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import React from 'react';
-import { shallow } from 'enzyme';
+import renderer from 'react-test-renderer';
+// import { shallow } from 'enzyme';
import Switch from '..';
-suite('components/Switch', () => {
- suite('disabled', () => {
+jest.mock('react-dom');
+
+describe('components/Switch', () => {
+ describe('disabled', () => {
test('when "false" a default checkbox is rendered', () => {
- const component = shallow(
);
- assert(component.find('input').length === 1);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('when "true" a disabled checkbox is rendered', () => {
- const component = shallow(
);
- assert(component.find('input').prop('disabled') === true);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
});
- suite('onValueChange', () => {
+ /*
+ describe('onValueChange', () => {
test('when value is "false" it receives "true"', () => {
- const handleValueChange = (value) => assert(value === true);
+ const handleValueChange = (value) => expect(value === true).toBeTruthy();
const component = shallow(
);
component.find('input').simulate('click');
});
test('when value is "true" it receives "false"', () => {
- const handleValueChange = (value) => assert(value === false);
+ const handleValueChange = (value) => expect(value === false).toBeTruthy();
const component = shallow(
);
component.find('input').simulate('click');
});
});
+ */
- suite('value', () => {
+ describe('value', () => {
test('when "false" an unchecked checkbox is rendered', () => {
- const component = shallow(
);
- assert(component.find('input').prop('checked') === false);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('when "true" a checked checkbox is rendered', () => {
- const component = shallow(
);
- assert(component.find('input').prop('checked') === true);
+ const component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
});
});
diff --git a/src/components/Text/__tests__/__snapshots__/index-test.js.snap b/src/components/Text/__tests__/__snapshots__/index-test.js.snap
new file mode 100644
index 00000000..e3d38c4e
--- /dev/null
+++ b/src/components/Text/__tests__/__snapshots__/index-test.js.snap
@@ -0,0 +1,86 @@
+exports[`components/Text prop "children" 1`] = `
+
+ children
+
+`;
+
+exports[`components/Text prop "selectable" 1`] = `
+
+`;
+
+exports[`components/Text prop "selectable" 2`] = `
+
+`;
diff --git a/src/components/Text/__tests__/index-test.js b/src/components/Text/__tests__/index-test.js
index 492a0a8e..7743f8dd 100644
--- a/src/components/Text/__tests__/index-test.js
+++ b/src/components/Text/__tests__/index-test.js
@@ -1,41 +1,23 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import React from 'react';
+import renderer from 'react-test-renderer';
import Text from '../';
-import { mount, shallow } from 'enzyme';
-suite('components/Text', () => {
+jest.mock('react-dom');
+
+describe('components/Text', () => {
test('prop "children"', () => {
- const children = 'children';
- const text = shallow(
{children});
- assert.equal(text.prop('children'), children);
+ const component = renderer.create(
children);
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "numberOfLines"');
- test('prop "onLayout"', (done) => {
- mount(
);
- function onLayout(e) {
- const { layout } = e.nativeEvent;
- assert.deepEqual(layout, { x: 0, y: 0, width: 0, height: 0 });
- done();
- }
- });
-
- test('prop "onPress"', (done) => {
- const text = mount(
);
- text.simulate('click');
- function onPress(e) {
- assert.ok(e.nativeEvent);
- done();
- }
- });
-
test('prop "selectable"', () => {
- let text = shallow(
);
- assert.equal(text.prop('style').userSelect, undefined);
- text = shallow(
);
- assert.equal(text.prop('style').userSelect, 'none');
+ let component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
+ component = renderer.create(
);
+ expect(component.toJSON()).toMatchSnapshot();
});
});
diff --git a/src/components/TextInput/__tests__/index-test.js b/src/components/TextInput/__tests__/index-test.js
index dd5b02a3..3f7e7c6b 100644
--- a/src/components/TextInput/__tests__/index-test.js
+++ b/src/components/TextInput/__tests__/index-test.js
@@ -1,6 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import React from 'react';
import StyleSheet from '../../../apis/StyleSheet';
import TextareaAutosize from 'react-textarea-autosize';
@@ -20,23 +19,23 @@ const testIfDocumentIsFocused = (message, fn) => {
}
};
-suite('components/TextInput', () => {
+describe('components/TextInput', () => {
test('prop "autoComplete"', () => {
// on
let input = findNativeInput(shallow(
));
- assert.equal(input.prop('autoComplete'), 'on');
+ expect(input.prop('autoComplete')).toEqual('on');
// off
input = findNativeInput(shallow(
));
- assert.equal(input.prop('autoComplete'), 'off');
+ expect(input.prop('autoComplete')).toEqual('off');
});
test('prop "autoFocus"', () => {
// false
let input = findNativeInput(mount(
));
- assert.equal(input.prop('autoFocus'), undefined);
+ expect(input.prop('autoFocus')).toEqual(undefined);
// true
input = findNativeInput(mount(
));
- assert.equal(input.prop('autoFocus'), true);
+ expect(input.prop('autoFocus')).toEqual(true);
});
testIfDocumentIsFocused('prop "clearTextOnFocus"', () => {
@@ -44,53 +43,53 @@ suite('components/TextInput', () => {
// false
let input = findNativeInput(mount(
));
input.simulate('focus');
- assert.equal(input.node.value, defaultValue);
+ expect(input.node.value).toEqual(defaultValue);
// true
input = findNativeInput(mount(
));
input.simulate('focus');
- assert.equal(input.node.value, '');
+ expect(input.node.value).toEqual('');
});
test('prop "defaultValue"', () => {
const defaultValue = 'defaultValue';
const input = findNativeInput(shallow(
));
- assert.equal(input.prop('defaultValue'), defaultValue);
+ expect(input.prop('defaultValue')).toEqual(defaultValue);
});
test('prop "editable"', () => {
// true
let input = findNativeInput(shallow(
));
- assert.equal(input.prop('readOnly'), false);
+ expect(input.prop('readOnly')).toEqual(false);
// false
input = findNativeInput(shallow(
));
- assert.equal(input.prop('readOnly'), true);
+ expect(input.prop('readOnly')).toEqual(true);
});
test('prop "keyboardType"', () => {
// default
let input = findNativeInput(shallow(
));
- assert.equal(input.prop('type'), 'text');
+ expect(input.prop('type')).toEqual('text');
input = findNativeInput(shallow(
));
- assert.equal(input.prop('type'), 'text');
+ expect(input.prop('type')).toEqual('text');
// email-address
input = findNativeInput(shallow(
));
- assert.equal(input.prop('type'), 'email');
+ expect(input.prop('type')).toEqual('email');
// numeric
input = findNativeInput(shallow(
));
- assert.equal(input.prop('type'), 'number');
+ expect(input.prop('type')).toEqual('number');
// phone-pad
input = findNativeInput(shallow(
));
- assert.equal(input.prop('type'), 'tel');
+ expect(input.prop('type')).toEqual('tel');
// url
input = findNativeInput(shallow(
));
- assert.equal(input.prop('type'), 'url');
+ expect(input.prop('type')).toEqual('url');
});
test('prop "maxLength"', () => {
let input = findNativeInput(shallow(
));
- assert.equal(input.prop('maxLength'), undefined);
+ expect(input.prop('maxLength')).toEqual(undefined);
input = findNativeInput(shallow(
));
- assert.equal(input.prop('maxLength'), '10');
+ expect(input.prop('maxLength')).toEqual(10);
});
test('prop "maxNumberOfLines"', () => {
@@ -107,25 +106,25 @@ suite('components/TextInput', () => {
value={generateValue()}
/>
));
- assert.equal(input.prop('maxRows'), 3);
+ expect(input.prop('maxRows')).toEqual(3);
});
test('prop "multiline"', () => {
// false
let input = findNativeInput(shallow(
));
- assert.equal(input.length, 1);
+ expect(input.length).toEqual(1);
// true
input = findNativeTextarea(shallow(
));
- assert.equal(input.length, 1);
+ expect(input.length).toEqual(1);
});
test('prop "numberOfLines"', () => {
// missing multiline
let input = findNativeInput(shallow(
));
- assert.equal(input.length, 1);
+ expect(input.length).toEqual(1);
// with multiline
input = findNativeTextarea(shallow(
));
- assert.equal(input.length, 1);
+ expect(input.length).toEqual(1);
input = findNativeTextarea(shallow(
{
numberOfLines={3}
/>
));
- assert.equal(input.prop('minRows'), 3);
+ expect(input.prop('minRows')).toEqual(3);
});
test('prop "onBlur"', (done) => {
const input = findNativeInput(mount());
input.simulate('blur');
function onBlur(e) {
- assert.ok(e);
+ expect(e).toBeTruthy();
done();
}
});
@@ -149,7 +148,7 @@ suite('components/TextInput', () => {
const input = findNativeInput(mount());
input.simulate('change');
function onChange(e) {
- assert.ok(e);
+ expect(e).toBeTruthy();
done();
}
});
@@ -159,7 +158,7 @@ suite('components/TextInput', () => {
const input = findNativeInput(mount());
input.simulate('change', { target: { value: newText } });
function onChangeText(text) {
- assert.equal(text, newText);
+ expect(text).toEqual(newText);
done();
}
});
@@ -168,7 +167,7 @@ suite('components/TextInput', () => {
const input = findNativeInput(mount());
input.simulate('focus');
function onFocus(e) {
- assert.ok(e);
+ expect(e).toBeTruthy();
done();
}
});
@@ -179,36 +178,36 @@ suite('components/TextInput', () => {
const input = findNativeInput(mount());
input.simulate('select', { target: { selectionStart: 0, selectionEnd: 3 } });
function onSelectionChange(e) {
- assert.equal(e.nativeEvent.selection.end, 3);
- assert.equal(e.nativeEvent.selection.start, 0);
+ expect(e.nativeEvent.selection.end).toEqual(3);
+ expect(e.nativeEvent.selection.start).toEqual(0);
done();
}
});
test('prop "placeholder"', () => {
let textInput = shallow();
- assert.equal(findPlaceholder(textInput).length, 0);
+ expect(findPlaceholder(textInput).length).toEqual(0);
textInput = shallow();
- assert.equal(findPlaceholder(textInput).length, 1);
+ expect(findPlaceholder(textInput).length).toEqual(1);
});
test('prop "placeholderTextColor"', () => {
let placeholderElement = findPlaceholder(shallow());
- assert.equal(StyleSheet.flatten(placeholderElement.prop('style')).color, 'darkgray');
+ expect(StyleSheet.flatten(placeholderElement.prop('style')).color).toEqual('darkgray');
placeholderElement = findPlaceholder(
shallow()
);
- assert.equal(StyleSheet.flatten(placeholderElement.prop('style')).color, 'red');
+ expect(StyleSheet.flatten(placeholderElement.prop('style')).color).toEqual('red');
});
test('prop "secureTextEntry"', () => {
let input = findNativeInput(shallow());
- assert.equal(input.prop('type'), 'password');
+ expect(input.prop('type')).toEqual('password');
// ignored for multiline
input = findNativeTextarea(shallow());
- assert.equal(input.prop('type'), undefined);
+ expect(input.prop('type')).toEqual(undefined);
});
testIfDocumentIsFocused('prop "selectTextOnFocus"', () => {
@@ -216,8 +215,8 @@ suite('components/TextInput', () => {
// false
let input = findNativeInput(mount());
input.node.focus();
- assert.equal(input.node.selectionEnd, 4);
- assert.equal(input.node.selectionStart, 4);
+ expect(input.node.selectionEnd).toEqual(4);
+ expect(input.node.selectionStart).toEqual(4);
// true
input = findNativeInput(mount());
// input.node.focus()
@@ -235,13 +234,13 @@ suite('components/TextInput', () => {
const textInput = shallow();
const input = findNativeInput(textInput);
const borderWidth = StyleSheet.flatten(textInput.prop('style')).borderWidth;
- assert.equal(borderWidth, 1, 'expected View styles to be applied to the "View"');
- assert.equal(input.prop('style').textAlign, 'center', 'expected Text styles to be applied to the "input"');
+ expect(borderWidth).toEqual(1);
+ expect(input.prop('style').textAlign).toEqual('center');
});
test('prop "value"', () => {
const value = 'value';
const input = findNativeInput(shallow());
- assert.equal(input.prop('value'), value);
+ expect(input.prop('value')).toEqual(value);
});
});
diff --git a/src/components/Touchable/__tests__/index-test.js b/src/components/Touchable/__tests__/index-test.js
index 9c48018f..86f9185f 100644
--- a/src/components/Touchable/__tests__/index-test.js
+++ b/src/components/Touchable/__tests__/index-test.js
@@ -1,5 +1,5 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-suite('components/Touchable', () => {
+describe('components/Touchable', () => {
test.skip('NO TEST COVERAGE', () => {});
});
diff --git a/src/components/View/__tests__/__snapshots__/index-test.js.snap b/src/components/View/__tests__/__snapshots__/index-test.js.snap
new file mode 100644
index 00000000..47fe8c99
--- /dev/null
+++ b/src/components/View/__tests__/__snapshots__/index-test.js.snap
@@ -0,0 +1,525 @@
+exports[`components/View prop "children" 1`] = `
+
+`;
+
+exports[`components/View prop "pointerEvents" 1`] = `
+
+`;
+
+exports[`components/View prop "style" 1`] = `
+
+`;
+
+exports[`components/View prop "style" 2`] = `
+
+`;
+
+exports[`components/View prop "style" 3`] = `
+
+`;
+
+exports[`components/View prop "style" 4`] = `
+
+`;
+
+exports[`components/View rendered element is a "div" by default 1`] = `
+
+`;
+
+exports[`components/View rendered element is a "span" when inside 1`] = `
+
+`;
diff --git a/src/components/View/__tests__/index-test.js b/src/components/View/__tests__/index-test.js
index 8bc6b7b0..137e2c8e 100644
--- a/src/components/View/__tests__/index-test.js
+++ b/src/components/View/__tests__/index-test.js
@@ -1,55 +1,46 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
-import includes from 'lodash/includes';
import React from 'react';
+import renderer from 'react-test-renderer';
import View from '../';
-import { mount, shallow } from 'enzyme';
-suite('components/View', () => {
- suite('rendered element', () => {
+jest.mock('react-dom');
+
+describe('components/View', () => {
+ describe('rendered element', () => {
test('is a "div" by default', () => {
- const view = shallow();
- assert.equal(view.is('div'), true);
+ const component = renderer.create();
+ expect(component.toJSON()).toMatchSnapshot();
});
test('is a "span" when inside ', () => {
- const view = mount();
- assert.equal(view.find('span').length, 1);
+ const component = renderer.create();
+ expect(component.toJSON()).toMatchSnapshot();
});
});
test('prop "children"', () => {
const children = ;
- const view = shallow({children});
- assert.equal(view.prop('children'), children);
- });
-
- test('prop "onLayout"', (done) => {
- mount();
- function onLayout(e) {
- const { layout } = e.nativeEvent;
- assert.deepEqual(layout, { x: 0, y: 0, width: 0, height: 0 });
- done();
- }
+ const component = renderer.create({children});
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "pointerEvents"', () => {
- const view = shallow();
- assert.ok(includes(view.prop('className'), '__style_pebo') === true);
+ const component = renderer.create();
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "style"', () => {
- const view = shallow();
- assert.equal(view.prop('style').flexShrink, 0);
+ let component = renderer.create();
+ expect(component.toJSON()).toMatchSnapshot();
- const flexView = shallow();
- assert.equal(flexView.prop('style').flexShrink, 1);
+ component = renderer.create();
+ expect(component.toJSON()).toMatchSnapshot();
- const flexShrinkView = shallow();
- assert.equal(flexShrinkView.prop('style').flexShrink, 1);
+ component = renderer.create();
+ expect(component.toJSON()).toMatchSnapshot();
- const flexAndShrinkView = shallow();
- assert.equal(flexAndShrinkView.prop('style').flexShrink, 2);
+ component = renderer.create();
+ expect(component.toJSON()).toMatchSnapshot();
});
});
diff --git a/src/modules/createDOMElement/__tests__/__snapshots__/index-test.js.snap b/src/modules/createDOMElement/__tests__/__snapshots__/index-test.js.snap
new file mode 100644
index 00000000..e0643671
--- /dev/null
+++ b/src/modules/createDOMElement/__tests__/__snapshots__/index-test.js.snap
@@ -0,0 +1,66 @@
+exports[`modules/createDOMElement prop "accessibilityLabel" 1`] = `
+
+`;
+
+exports[`modules/createDOMElement prop "accessibilityLiveRegion" 1`] = `
+
+`;
+
+exports[`modules/createDOMElement prop "accessibilityRole" 1`] = `
+
+`;
+
+exports[`modules/createDOMElement prop "accessibilityRole" 2`] = `
+
+`;
+
+exports[`modules/createDOMElement prop "accessible" 1`] = `
+
+`;
+
+exports[`modules/createDOMElement prop "accessible" 2`] = `
+
+`;
+
+exports[`modules/createDOMElement prop "accessible" 3`] = `
+
+`;
+
+exports[`modules/createDOMElement prop "testID" 1`] = `
+
+`;
+
+exports[`modules/createDOMElement renders correct DOM element 1`] = `
+
+`;
+
+exports[`modules/createDOMElement renders correct DOM element 2`] = `
+
+`;
diff --git a/src/modules/createDOMElement/__tests__/index-test.js b/src/modules/createDOMElement/__tests__/index-test.js
index 94ea1856..9aecf9b5 100644
--- a/src/modules/createDOMElement/__tests__/index-test.js
+++ b/src/modules/createDOMElement/__tests__/index-test.js
@@ -1,60 +1,50 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import createDOMElement from '..';
-import { shallow } from 'enzyme';
+import renderer from 'react-test-renderer';
-suite('modules/createDOMElement', () => {
+describe('modules/createDOMElement', () => {
test('renders correct DOM element', () => {
- let element = shallow(createDOMElement('span'));
- assert.equal(element.is('span'), true);
- element = shallow(createDOMElement('main'));
- assert.equal(element.is('main'), true);
+ let component = renderer.create(createDOMElement('span'));
+ expect(component.toJSON()).toMatchSnapshot();
+ component = renderer.create(createDOMElement('main'));
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "accessibilityLabel"', () => {
const accessibilityLabel = 'accessibilityLabel';
- const element = shallow(createDOMElement('span', { accessibilityLabel }));
- assert.equal(element.prop('aria-label'), accessibilityLabel);
+ const component = renderer.create(createDOMElement('span', { accessibilityLabel }));
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "accessibilityLiveRegion"', () => {
const accessibilityLiveRegion = 'polite';
- const element = shallow(createDOMElement('span', { accessibilityLiveRegion }));
- assert.equal(element.prop('aria-live'), accessibilityLiveRegion);
+ const component = renderer.create(createDOMElement('span', { accessibilityLiveRegion }));
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "accessibilityRole"', () => {
const accessibilityRole = 'banner';
- let element = shallow(createDOMElement('span', { accessibilityRole }));
- assert.equal(element.prop('role'), accessibilityRole);
- assert.equal(element.is('header'), true);
-
- const button = 'button';
- element = shallow(createDOMElement('span', { accessibilityRole: 'button' }));
- assert.equal(element.prop('type'), button);
- assert.equal(element.is('button'), true);
+ let component = renderer.create(createDOMElement('span', { accessibilityRole }));
+ expect(component.toJSON()).toMatchSnapshot();
+ component = renderer.create(createDOMElement('span', { accessibilityRole: 'button' }));
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "accessible"', () => {
// accessible (implicit)
- let element = shallow(createDOMElement('span', {}));
- assert.equal(element.prop('aria-hidden'), null);
+ let component = renderer.create(createDOMElement('span', {}));
+ expect(component.toJSON()).toMatchSnapshot();
// accessible (explicit)
- element = shallow(createDOMElement('span', { accessible: true }));
- assert.equal(element.prop('aria-hidden'), null);
+ component = renderer.create(createDOMElement('span', { accessible: true }));
+ expect(component.toJSON()).toMatchSnapshot();
// not accessible
- element = shallow(createDOMElement('span', { accessible: false }));
- assert.equal(element.prop('aria-hidden'), true);
+ component = renderer.create(createDOMElement('span', { accessible: false }));
+ expect(component.toJSON()).toMatchSnapshot();
});
test('prop "testID"', () => {
- // no testID
- let element = shallow(createDOMElement('span', {}));
- assert.equal(element.prop('data-testid'), null);
- // with testID
- const testID = 'Example.testID';
- element = shallow(createDOMElement('span', { testID }));
- assert.equal(element.prop('data-testid'), testID);
+ const component = renderer.create(createDOMElement('span', { testID: 'Example.testID' }));
+ expect(component.toJSON()).toMatchSnapshot();
});
});
diff --git a/src/modules/createDOMElement/index.js b/src/modules/createDOMElement/index.js
index e4392753..cb361d65 100644
--- a/src/modules/createDOMElement/index.js
+++ b/src/modules/createDOMElement/index.js
@@ -30,18 +30,24 @@ const createDOMElement = (component, rnProps = {}) => {
const accessibilityComponent = accessibilityRole && roleComponents[accessibilityRole];
const Component = accessibilityComponent || component;
+ const domProps = {
+ ...other,
+ ...StyleSheet.resolve(other)
+ };
+ if (!accessible) { domProps['aria-hidden'] = true; }
+ if (accessibilityLabel) { domProps['aria-label'] = accessibilityLabel; }
+ if (accessibilityLiveRegion) { domProps['aria-live'] = accessibilityLiveRegion; }
+ if (testID) { domProps['data-testid'] = testID; }
+ if (accessibilityRole) {
+ domProps.role = accessibilityRole;
+ if (accessibilityRole === 'button') {
+ domProps.type = 'button';
+ }
+ }
+ if (type) { domProps.type = type; }
return (
-
+
);
};
diff --git a/src/modules/flattenStyle/__tests__/__snapshots__/index-test.js.snap b/src/modules/flattenStyle/__tests__/__snapshots__/index-test.js.snap
new file mode 100644
index 00000000..87c4aaba
--- /dev/null
+++ b/src/modules/flattenStyle/__tests__/__snapshots__/index-test.js.snap
@@ -0,0 +1,26 @@
+exports[`modules/flattenStyle should merge style objects 1`] = `
+Object {
+ "opacity": 1,
+ "order": 2,
+}
+`;
+
+exports[`modules/flattenStyle should override style properties 1`] = `
+Object {
+ "backgroundColor": "#023c69",
+ "order": null,
+}
+`;
+
+exports[`modules/flattenStyle should overwrite properties with \`undefined\` 1`] = `
+Object {
+ "backgroundColor": undefined,
+}
+`;
+
+exports[`modules/flattenStyle should recursively flatten arrays 1`] = `
+Object {
+ "opacity": 1,
+ "order": 3,
+}
+`;
diff --git a/src/modules/flattenStyle/__tests__/index-test.js b/src/modules/flattenStyle/__tests__/index-test.js
index 035617d1..818e5216 100644
--- a/src/modules/flattenStyle/__tests__/index-test.js
+++ b/src/modules/flattenStyle/__tests__/index-test.js
@@ -1,4 +1,4 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
/**
* Copyright (c) 2015-present, Facebook, Inc.
@@ -9,43 +9,44 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import assert from 'assert';
import flattenStyle from '..';
-suite('modules/flattenStyle', () => {
+describe('modules/flattenStyle', () => {
test('should merge style objects', () => {
- const style1 = { opacity: 1 };
- const style2 = { order: 2 };
- const flatStyle = flattenStyle([ style1, style2 ]);
- assert.equal(flatStyle.opacity, 1);
- assert.equal(flatStyle.order, 2);
+ const style = flattenStyle([
+ { opacity: 1 },
+ { order: 2 }
+ ]);
+ expect(style).toMatchSnapshot();
});
test('should override style properties', () => {
- const style1 = { backgroundColor: '#000', order: 1 };
- const style2 = { backgroundColor: '#023c69', order: null };
- const flatStyle = flattenStyle([ style1, style2 ]);
- assert.equal(flatStyle.backgroundColor, '#023c69');
- assert.strictEqual(flatStyle.order, null);
+ const style = flattenStyle([
+ { backgroundColor: '#000', order: 1 },
+ { backgroundColor: '#023c69', order: null }
+ ]);
+ expect(style).toMatchSnapshot();
});
test('should overwrite properties with `undefined`', () => {
- const style1 = { backgroundColor: '#000' };
- const style2 = { backgroundColor: undefined };
- const flatStyle = flattenStyle([ style1, style2 ]);
- assert.strictEqual(flatStyle.backgroundColor, undefined);
+ const style = flattenStyle([
+ { backgroundColor: '#000' },
+ { backgroundColor: undefined }
+ ]);
+ expect(style).toMatchSnapshot();
});
test('should not fail on falsy values', () => {
- assert.doesNotThrow(() => flattenStyle([ null, false, undefined ]));
+ expect(() => flattenStyle([ null, false, undefined ])).not.toThrow();
});
test('should recursively flatten arrays', () => {
- const style1 = { order: 2 };
- const style2 = { opacity: 1 };
- const style3 = { order: 3 };
- const flatStyle = flattenStyle([ null, [], [ style1, style2 ], style3 ]);
- assert.equal(flatStyle.order, 3);
- assert.equal(flatStyle.opacity, 1);
+ const style = flattenStyle([
+ null,
+ [],
+ [ { order: 2 }, { opacity: 1 } ],
+ { order: 3 }
+ ]);
+ expect(style).toMatchSnapshot();
});
});
diff --git a/src/modules/multiplyStyleLengthValue/__tests__/index-test.js b/src/modules/multiplyStyleLengthValue/__tests__/index-test.js
index a8090d7b..a7ae061a 100644
--- a/src/modules/multiplyStyleLengthValue/__tests__/index-test.js
+++ b/src/modules/multiplyStyleLengthValue/__tests__/index-test.js
@@ -1,19 +1,18 @@
-/* eslint-env mocha */
+/* eslint-env jasmine, jest */
-import assert from 'assert';
import multiplyStyleLengthValue from '..';
-suite('modules/multiplyStyleLengthValue', () => {
+describe('modules/multiplyStyleLengthValue', () => {
test('number', () => {
- assert.equal(multiplyStyleLengthValue(2, -1), -2);
- assert.equal(multiplyStyleLengthValue(2, 2), 4);
- assert.equal(multiplyStyleLengthValue(2.5, 2), 5);
+ expect(multiplyStyleLengthValue(2, -1)).toEqual(-2);
+ expect(multiplyStyleLengthValue(2, 2)).toEqual(4);
+ expect(multiplyStyleLengthValue(2.5, 2)).toEqual(5);
});
test('length', () => {
- assert.equal(multiplyStyleLengthValue('2rem', -1), '-2rem');
- assert.equal(multiplyStyleLengthValue('2px', 2), '4px');
- assert.equal(multiplyStyleLengthValue('2.5em', 2), '5em');
- assert.equal(multiplyStyleLengthValue('2e3px', 2), '4000px');
+ expect(multiplyStyleLengthValue('2rem', -1)).toEqual('-2rem');
+ expect(multiplyStyleLengthValue('2px', 2)).toEqual('4px');
+ expect(multiplyStyleLengthValue('2.5em', 2)).toEqual('5em');
+ expect(multiplyStyleLengthValue('2e3px', 2)).toEqual('4000px');
});
});