Skip to content

Commit

Permalink
Merge pull request #4 from icd2k3/fix-enum-and-logging
Browse files Browse the repository at this point in the history
Fix enum type warning and better warning messages
  • Loading branch information
icd2k3 authored Feb 17, 2018
2 parents 7c5b922 + 135234b commit 303d23b
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 232 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ComponentWithoutProps from '../ComponentWithoutProps';
import snap from 'jest-auto-snapshots';
import ComponentWithoutProps from '../ComponentWithoutProps';

snap(ComponentWithoutProps, '../ComponentWithoutProps.jsx');
2 changes: 1 addition & 1 deletion examples/CustomProps/__tests__/CustomProps.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import snap from 'jest-auto-snapshots';
import CustomProps from '../CustomProps';

snap(CustomProps, '../CustomProps.jsx', { fixturesByPropType: { customProp: 'customproptest' } });
snap(CustomProps, '../CustomProps.jsx', { fixturesByPropType: { customPropType: 'customproptest' } });
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`jest-auto-snapshots > CustomProps Matches snapshot when passed all props 1`] = `<div />`;
exports[`jest-auto-snapshots > CustomProps Matches snapshot when passed all props 1`] = `
<div>
customproptest
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports[`jest-auto-snapshots > ShallowProps Matches snapshot when boolean prop "
</button>
jest-auto-snapshots String Fixture
1
'News'
News
</div>
`;

Expand All @@ -37,7 +37,7 @@ exports[`jest-auto-snapshots > ShallowProps Matches snapshot when passed all pro
</button>
jest-auto-snapshots String Fixture
1
'News'
News
</div>
`;

Expand All @@ -55,6 +55,6 @@ exports[`jest-auto-snapshots > ShallowProps Matches snapshot when passed only re
button
</button>
999
'News'
News
</div>
`;
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ module.exports = {
setupFiles: ['./jest.setup.js'],
snapshotSerializers: ['enzyme-to-json/serializer'],
testMatch: ['**/*.test.js?(x)'],
verbose: false,
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-auto-snapshots",
"version": "2.0.1",
"version": "2.1.0",
"description": "Fully automated Jest snapshot tests for React components",
"main": "./dist/index.js",
"repository": "git@github.com:icd2k3/jest-auto-snapshots.git",
Expand Down Expand Up @@ -49,7 +49,7 @@
"prepublishOnly": "npm run build",
"build": "babel src --out-dir dist",
"install-hooks": "git config core.hooksPath .githooks",
"test": "NODE_ENV=test && ./node_modules/.bin/jest --config=./jest.config.js --verbose",
"test": "NODE_ENV=test && ./node_modules/.bin/jest --config=./jest.config.js",
"lint": "./node_modules/.bin/eslint './src/**/*.js' './examples/**/*.js' './examples/**/*.jsx'",
"travis": "jest && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
}
Expand Down
52 changes: 24 additions & 28 deletions src/__tests__/getFixture.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,37 @@ describe('getFixture', () => {

describe('custom fixture prop type', () => {
it('Should return the correct fixture', () => {
expect(
getFixture(
{
name: 'mockCustomPropType',
key: 'key',
raw: 'mockCustomPropType',
expect(getFixture(
{
name: 'mockCustomPropType',
key: 'key',
raw: 'mockCustomPropType',
},
'key',
mergeConfig({
fixturesByPropType: {
mockCustomPropType: 'mockCustomFixture',
},
'key',
mergeConfig({
fixturesByPropType: {
mockCustomPropType: 'mockCustomFixture',
},
}),
),
).toBe('mockCustomFixture');
}),
)).toBe('mockCustomFixture');
});
});

describe('custom fixture prop key', () => {
it('Should return the correct fixture', () => {
expect(
getFixture(
{
name: 'string',
key: 'mockKey',
raw: 'string',
expect(getFixture(
{
name: 'string',
key: 'mockKey',
raw: 'string',
},
'mockKey',
mergeConfig({
fixturesByPropKey: {
mockKey: 'mockCustomKeyFixture',
},
'mockKey',
mergeConfig({
fixturesByPropKey: {
mockKey: 'mockCustomKeyFixture',
},
}),
),
).toBe('mockCustomKeyFixture');
}),
)).toBe('mockCustomKeyFixture');
});
});
});
2 changes: 1 addition & 1 deletion src/getFixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const getFixture = ({ name, raw, value }, key, config) => {
[shapePropKey]: getFixture(value[shapePropKey], key, config),
}), {});
case 'enum': // aka oneOf
return value[0].value;
return value[0].value.slice(1, -1);
case 'arrayOf':
return [getFixture(value, key, config)];
case 'union':
Expand Down
6 changes: 3 additions & 3 deletions src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ERROR = Object.freeze({
`,
MULTIPLE_COMPONENTS_NOT_FOUND: (name, file) => `
The Component \`name\` could not be found in:
\`${file}\`.
'${file}'.
It looks like there are multiple exported components in this file.
In this case you probably need to add a comment above your component definition:
Expand All @@ -24,10 +24,10 @@ export const ERROR = Object.freeze({
This is due to a limitation in react-docgen to be able to parse this Component's propTypes.
`,
PROP_TYPE_UNRECOGNIZED: (key, raw) => `
The prop \`${key}\` of type \`${raw}\` is unrecognized.
The prop '${key}' of type '${raw}' is unrecognized.
To fix this warning you can either inject the prop in the test:
\`snap(Component, { props: { ${key}: 'value' } })\`
\`snap(Component, ../Component.jsx, { fixturesByPropType: { ${raw}: 'value' } })\`
or define a root-level prop fixture handler (see readme)
`,
Expand Down
Loading

0 comments on commit 303d23b

Please sign in to comment.