Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace warning #1192

Merged
merged 4 commits into from Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions .size-snapshot.json
@@ -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
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/FastField.tsx
@@ -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> {
Expand Down
3 changes: 2 additions & 1 deletion src/Field.tsx
@@ -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';

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Formik.tsx
@@ -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,
Expand Down Expand Up @@ -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}
Expand Down
20 changes: 10 additions & 10 deletions test/Field.test.tsx
Expand Up @@ -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:'
);
}
Expand All @@ -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:'
);
});
Expand Down
14 changes: 7 additions & 7 deletions test/Formik.test.tsx
Expand Up @@ -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;
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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 () => {
Expand Down
4 changes: 4 additions & 0 deletions types/index.d.ts
@@ -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>(
Expand Down
9 changes: 5 additions & 4 deletions yarn.lock
Expand Up @@ -380,10 +380,6 @@
"@types/prop-types" "*"
csstype "^2.2.0"

"@types/warning@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/warning/-/warning-3.0.0.tgz#0d2501268ad8f9962b740d387c4654f5f8e23e52"

"@types/yup@^0.24.9":
version "0.24.9"
resolved "https://registry.yarnpkg.com/@types/yup/-/yup-0.24.9.tgz#da98f4b38eec7ca72146e7042679c8c8628896fa"
Expand Down Expand Up @@ -8933,6 +8929,11 @@ timers-browserify@^2.0.4:
dependencies:
setimmediate "^1.0.4"

tiny-warning@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.2.tgz#1dfae771ee1a04396bdfde27a3adcebc6b648b28"
integrity sha512-rru86D9CpQRLvsFG5XFdy0KdLAvjdQDyZCsRcuu60WtzFylDM3eAWSxEVz5kzL2Gp544XiUvPbVKtOA/txLi9Q==

tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
Expand Down