Permalink
Browse files

Replace warning (#1192)

* Replace warning with tiny-warning

* Implement warning in source

* Use tiny-warning

* Bump tiny-warning to 1.0.2
  • Loading branch information...
jaredpalmer committed Dec 18, 2018
1 parent 5f9afc1 commit 13954fdd10070f727a0259dbbf98824cb980fa92
Showing with 50 additions and 44 deletions.
  1. +16 −16 .size-snapshot.json
  2. +2 −3 package.json
  3. +2 −1 src/FastField.tsx
  4. +2 −1 src/Field.tsx
  5. +2 −2 src/Formik.tsx
  6. +10 −10 test/Field.test.tsx
  7. +7 −7 test/Formik.test.tsx
  8. +4 −0 types/index.d.ts
  9. +5 −4 yarn.lock
@@ -1,35 +1,35 @@
{
"./dist/formik.umd.production.js": {
"bundled": 141767,
"bundled": 141423,
"minified": 39046,
"gzipped": 11848
},
"./dist/formik.umd.development.js": {
"bundled": 172955,
"minified": 49892,
"gzipped": 15033
"bundled": 171603,
"minified": 49483,
"gzipped": 14950
},
"./dist/formik.cjs.production.js": {
"bundled": 42373,
"minified": 21473,
"gzipped": 5381
"bundled": 42377,
"minified": 21477,
"gzipped": 5386
},
"./dist/formik.cjs.development.js": {
"bundled": 43261,
"minified": 22356,
"gzipped": 5726
"bundled": 43265,
"minified": 22360,
"gzipped": 5725
},
"dist/formik.esm.js": {
"bundled": 39122,
"minified": 21745,
"gzipped": 5603,
"bundled": 39126,
"minified": 21749,
"gzipped": 5602,
"treeshaked": {
"rollup": {
"code": 766,
"import_statements": 344
"code": 771,
"import_statements": 349
},
"webpack": {
"code": 3439
"code": 3444
}
}
}
@@ -48,8 +48,8 @@
"lodash-es": "^4.17.11",
"prop-types": "^15.6.1",
"react-fast-compare": "^2.0.1",
"tslib": "^1.9.3",
"warning": "^3.0.0"
"tiny-warning": "^1.0.2",
"tslib": "^1.9.3"
},
"optionalDependencies": {},
"resolutions": {
@@ -64,7 +64,6 @@
"@types/lodash": "^4.14.119",
"@types/react": "^16.7.6",
"@types/react-dom": "^16.0.9",
"@types/warning": "^3.0.0",
"@types/yup": "^0.24.9",
"all-contributors-cli": "^4.4.0",
"awesome-typescript-loader": "^3.4.1",
@@ -1,11 +1,12 @@
import * as React from 'react';
import warning from 'warning';

import { connect } from './connect';
import {
FormikProps,
GenericFieldHTMLAttributes,
FormikContext,
} from './types';
import warning from 'tiny-warning';
import { getIn, isEmptyChildren, isFunction } from './utils';

export interface FastFieldProps<V = any> {
@@ -1,11 +1,12 @@
import * as React from 'react';
import warning from 'warning';

import { connect } from './connect';
import {
FormikProps,
GenericFieldHTMLAttributes,
FormikContext,
} from './types';
import warning from 'tiny-warning';
import { getIn, isEmptyChildren, isFunction } from './utils';

/**
@@ -1,8 +1,8 @@
import * as React from 'react';
import isEqual from 'react-fast-compare';
import warning from 'warning';
import deepmerge from 'deepmerge';
import { FormikProvider } from './connect';
import warning from 'tiny-warning';
import {
FormikActions,
FormikConfig,
@@ -657,7 +657,7 @@ function warnAboutMissingIdentifier({
documentationAnchorLink: string;
handlerName: string;
}) {
console.error(
console.warn(
`Warning: Formik called \`${handlerName}\`, but you forgot to pass an \`id\` or \`name\` attribute to your input:
${htmlContent}
@@ -259,14 +259,14 @@ describe('Field / FastField', () => {
cases(
'warns if both string component and children as a function',
renderField => {
global.console.error = jest.fn();
global.console.warn = jest.fn();

renderField({
component: 'select',
children: () => <option value="Jared">{TEXT}</option>,
});

expect((global.console.error as jest.Mock).mock.calls[0][0]).toContain(
expect((global.console.warn as jest.Mock).mock.calls[0][0]).toContain(
'Warning:'
);
}
@@ -275,54 +275,54 @@ describe('Field / FastField', () => {
cases(
'warns if both non-string component and children children as a function',
renderField => {
global.console.error = jest.fn();
global.console.warn = jest.fn();

renderField({
component: () => null,
children: () => <option value="Jared">{TEXT}</option>,
});

expect((global.console.error as jest.Mock).mock.calls[0][0]).toContain(
expect((global.console.warn as jest.Mock).mock.calls[0][0]).toContain(
'Warning:'
);
}
);

cases('warns if both string component and render', renderField => {
global.console.error = jest.fn();
global.console.warn = jest.fn();

renderField({
component: 'textarea',
render: () => <option value="Jared">{TEXT}</option>,
});

expect((global.console.error as jest.Mock).mock.calls[0][0]).toContain(
expect((global.console.warn as jest.Mock).mock.calls[0][0]).toContain(
'Warning:'
);
});

cases('warns if both non-string component and render', renderField => {
global.console.error = jest.fn();
global.console.warn = jest.fn();

renderField({
component: () => null,
render: () => <option value="Jared">{TEXT}</option>,
});

expect((global.console.error as jest.Mock).mock.calls[0][0]).toContain(
expect((global.console.warn as jest.Mock).mock.calls[0][0]).toContain(
'Warning:'
);
});

cases('warns if both children and render', renderField => {
global.console.error = jest.fn();
global.console.warn = jest.fn();

renderField({
children: <div>{TEXT}</div>,
render: () => <div>{TEXT}</div>,
});

expect((global.console.error as jest.Mock).mock.calls[0][0]).toContain(
expect((global.console.warn as jest.Mock).mock.calls[0][0]).toContain(
'Warning:'
);
});
@@ -5,7 +5,7 @@ import * as Yup from 'yup';
import { Formik, FormikProps, FormikConfig } from '../src';
import { noop } from './testHelpers';

jest.spyOn(global.console, 'error');
jest.spyOn(global.console, 'warn');

interface Values {
name: string;
@@ -878,14 +878,14 @@ describe('<Formik>', () => {

fireEvent.submit(getByTestId('form'));

expect(global.console.error).toHaveBeenCalledWith(
expect(global.console.warn).toHaveBeenCalledWith(
expect.stringMatching(
/Warning: You submitted a Formik form using a button with an unspecified `type./
)
);

button.blur(); // unsets activeElement
(global.console.error as jest.Mock<{}>).mockClear();
(global.console.warn as jest.Mock<{}>).mockClear();
});

it('should not warn when button has type submit', () => {
@@ -910,14 +910,14 @@ describe('<Formik>', () => {

fireEvent.submit(getByTestId('form'));

expect(global.console.error).not.toHaveBeenCalledWith(
expect(global.console.warn).not.toHaveBeenCalledWith(
expect.stringMatching(
/Warning: You submitted a Formik form using a button with an unspecified type./
)
);

button.blur(); // unsets activeElement
(global.console.error as jest.Mock<{}>).mockClear();
(global.console.warn as jest.Mock<{}>).mockClear();
});

it('should not warn when activeElement is not a button', () => {
@@ -942,14 +942,14 @@ describe('<Formik>', () => {

fireEvent.submit(getByTestId('form'));

expect(global.console.error).not.toHaveBeenCalledWith(
expect(global.console.warn).not.toHaveBeenCalledWith(
expect.stringMatching(
/Warning: You submitted a Formik form using a button with an unspecified type./
)
);

input.blur(); // unsets activeElement
(global.console.error as jest.Mock<{}>).mockClear();
(global.console.warn as jest.Mock<{}>).mockClear();
});

it('submit count increments', async () => {
@@ -1,4 +1,8 @@
declare module 'react-testing-library';
declare module 'tiny-warning' {
export default function warning(condition: any, message: string): void;
}

declare module 'react-lifecycles-compat' {
import React from 'react';
export function polyfill<P>(

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 13954fd

Please sign in to comment.