Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

terra-base

Package Overview
Dependencies
Maintainers
9
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

terra-base - npm Package Compare versions

Comparing version 5.39.0 to 5.40.0

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Changelog

## 5.40.0 - (September 29, 2020)
* Added
* Added `throwOnI18nLoadError` prop to opt into logging and throwing the error when i18n data fails to load instead of only logging the error to the console
## 5.39.0 - (August 4, 2020)

@@ -7,0 +12,0 @@

23

lib/Base.js

@@ -74,7 +74,11 @@ "use strict";

/**
* The component(s) that will be wrapped by `<Base />` ONLY
* in the event that translations have not been loaded yet.
* NOTE: Absolutely no locale-dependent logic should be
* utilized in this placeholder.
* Whether or not the error should be logged and thrown if something goes wrong. When false, the error will only be logged to the
* console an error.
*/
throwOnI18nLoadError: _propTypes.default.bool,
/**
* The component(s) that will be wrapped by `<Base />` ONLY in the event that translations have not been loaded yet.
* NOTE: Absolutely no locale-dependent logic should be utilized in this placeholder.
*/
translationsLoadingPlaceholder: _propTypes.default.node

@@ -84,3 +88,4 @@ };

customMessages: {},
strictMode: false
strictMode: false,
throwOnI18nLoadError: false
};

@@ -116,2 +121,6 @@

console.error(e);
if (this.props.throwOnI18nLoadError) {
throw e;
}
}

@@ -129,2 +138,6 @@ }

console.error(e);
if (this.props.throwOnI18nLoadError) {
throw e;
}
}

@@ -131,0 +144,0 @@ }

{
"name": "terra-base",
"main": "lib/Base.js",
"version": "5.39.0",
"version": "5.40.0",
"description": "The base component sets minimal global styles for an application.",

@@ -32,3 +32,3 @@ "repository": {

"prop-types": "^15.5.8",
"terra-i18n": "^4.32.0"
"terra-i18n": "^4.33.0"
},

@@ -48,3 +48,3 @@ "scripts": {

},
"gitHead": "25fa65c7df029c2a5341095ada3341e558a3257b"
"gitHead": "95141beff02c3e36ad8e83433fdda3881fcc083a"
}

@@ -29,7 +29,10 @@ import React from 'react';

/**
* The component(s) that will be wrapped by `<Base />` ONLY
* in the event that translations have not been loaded yet.
* NOTE: Absolutely no locale-dependent logic should be
* utilized in this placeholder.
* Whether or not the error should be logged and thrown if something goes wrong. When false, the error will only be logged to the
* console an error.
*/
throwOnI18nLoadError: PropTypes.bool,
/**
* The component(s) that will be wrapped by `<Base />` ONLY in the event that translations have not been loaded yet.
* NOTE: Absolutely no locale-dependent logic should be utilized in this placeholder.
*/
translationsLoadingPlaceholder: PropTypes.node,

@@ -41,2 +44,3 @@ };

strictMode: false,
throwOnI18nLoadError: false,
};

@@ -61,2 +65,6 @@

console.error(e);
if (this.props.throwOnI18nLoadError) {
throw e;
}
}

@@ -73,2 +81,6 @@ }

console.error(e);
if (this.props.throwOnI18nLoadError) {
throw e;
}
}

@@ -75,0 +87,0 @@ }

import React from 'react';
import * as terraI18n from 'terra-i18n';
import Base from '../../src/Base';
jest.mock('terra-i18n');
// Missing locale test

@@ -8,7 +12,4 @@ it('throws error for missing required locale', () => {

try {
shallow(<Base customMessages={messages}>String</Base>);
} catch (e) {
expect(e.message).toContain('The prop `locale` is marked as required in `Base`');
}
expect(() => shallow(<Base customMessages={messages}>String</Base>))
.toThrowError(/The prop `locale` is marked as required in `Base`/);
});

@@ -23,3 +24,2 @@

it('should support rendering an array of children', () => {
/* eslint-disable comma-dangle */
const base = shallow(

@@ -29,6 +29,5 @@ <Base>

<div>2</div>
</Base>
</Base>,
);
expect(base).toMatchSnapshot();
/* eslint-enable comma-dangle */
});

@@ -40,1 +39,41 @@

});
describe('base handles i18n data loading', () => {
beforeAll(() => {
// eslint-disable-next-line no-console
console.error = jest.fn();
});
beforeEach(() => {
// eslint-disable-next-line no-console
console.error.mockClear();
});
it('renders as expected when i18n data loads successfully', () => {
terraI18n.i18nLoader = jest.fn();
expect(() => shallow(<Base locale="en">String</Base>)).not.toThrowError();
expect(terraI18n.i18nLoader).toHaveBeenCalled();
// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled();
});
it('logs error when i18n data fails to load', () => {
terraI18n.i18nLoader = jest.fn(() => {
throw new Error('failed to load data.');
});
expect(() => shallow(<Base locale="en">String</Base>)).not.toThrowError();
expect(terraI18n.i18nLoader).toHaveBeenCalled();
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalled();
});
it('throws error when i18n data fails to load', () => {
terraI18n.i18nLoader = jest.fn(() => {
throw new Error('failed to load data.');
});
expect(() => shallow(<Base locale="en" throwOnI18nLoadError>String</Base>)).toThrowError();
expect(terraI18n.i18nLoader).toHaveBeenCalled();
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalled();
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc