This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and use method to test a package's exported values
Cherry pick changes to `psammead-test-helpers` from the POC PR - #224
- Loading branch information
Phil Lee
committed
Jan 4, 2019
1 parent
fc55cdc
commit b0a8c0b
Showing
6 changed files
with
179 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
packages/utilities/psammead-test-helpers/index.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import * as testHelpers from '.'; | ||
import * as testHelpersFromSrc from './src/index'; | ||
|
||
const testHelpersExpectedExports = { | ||
shouldMatchSnapshot: 'function', | ||
shallowRender: 'function', | ||
shouldShallowMatchSnapshot: 'function', | ||
isNull: 'function', | ||
testUtilityPackages: 'function', | ||
}; | ||
|
||
const expectedExports = { testHelpers: testHelpersExpectedExports }; | ||
|
||
const actualExports = { testHelpers }; | ||
|
||
const actualExportsFromSrc = { testHelpers: testHelpersFromSrc }; | ||
|
||
const ensureErrorWhenMissingExport = testHelperMethod => { | ||
// missing export in the expected | ||
const actualWithAll = { utility: { foo: {}, bar: {} } }; | ||
const expectedMissing = { utility: { bar: {} } }; | ||
|
||
expect(() => { | ||
testHelperMethod(actualWithAll, expectedMissing, 'testing'); | ||
}).toThrowError( | ||
"Missing value 'foo' in the expected export for 'testing/utility'.", | ||
); | ||
|
||
// missing export in the actual | ||
const actualMissing = { utility: { foo: {} } }; | ||
const expectedWithAll = { utility: { bar: {}, foo: {} } }; | ||
|
||
expect(() => { | ||
testHelperMethod(actualMissing, expectedWithAll, 'testing'); | ||
}).toThrowError( | ||
"Missing value 'bar' in the actual export for 'testing/utility'.", | ||
); | ||
}; | ||
|
||
const ensureErrorWhenMissingFileDefinition = testHelperMethod => { | ||
// missing export in the expected | ||
const actualWithAll = { | ||
utilityOne: { key: {} }, | ||
utilityTwo: { key: {} }, | ||
}; | ||
const expectedMissing = { | ||
utilityOne: { key: {} }, | ||
}; | ||
|
||
expect(() => { | ||
testHelperMethod(actualWithAll, expectedMissing, 'testing'); | ||
}).toThrowError( | ||
"Missing value 'utilityTwo' in the expected utilities for 'testing'.", | ||
); | ||
|
||
// missing export in the actual | ||
const actualMissing = { | ||
utilityOne: { key: {} }, | ||
}; | ||
const expectedWithAll = { | ||
utilityOne: { key: {} }, | ||
utilityTwo: { key: {} }, | ||
}; | ||
|
||
expect(() => { | ||
testHelperMethod(actualMissing, expectedWithAll, 'testing'); | ||
}).toThrowError( | ||
"Missing value 'utilityTwo' in the actual utilities for 'testing'.", | ||
); | ||
}; | ||
|
||
describe('Psammead test helpers', () => { | ||
it('should test all the utility exports exist and are the correct type', () => { | ||
testHelpers.testUtilityPackages( | ||
actualExports, | ||
expectedExports, | ||
'psammead-test-helpers', | ||
); | ||
}); | ||
|
||
it('should test all the utility exports exist and are the correct type when coming from src/', () => { | ||
testHelpers.testUtilityPackages( | ||
actualExportsFromSrc, | ||
expectedExports, | ||
'psammead-test-helpers', | ||
); | ||
}); | ||
|
||
it('should error if expectedExport is missing an export compared to the actual export', () => { | ||
ensureErrorWhenMissingExport(testHelpers.testUtilityPackages); | ||
}); | ||
|
||
it('should error if expectedExport is missing an export compared to the actual export when coming from /src', () => { | ||
ensureErrorWhenMissingExport(testHelpersFromSrc.testUtilityPackages); | ||
}); | ||
|
||
it('should error if file definition is missing in the expectation', () => { | ||
ensureErrorWhenMissingFileDefinition(testHelpers.testUtilityPackages); | ||
}); | ||
|
||
it('should error if file definition is missing in the expectation when coming from /src', () => { | ||
ensureErrorWhenMissingFileDefinition( | ||
testHelpersFromSrc.testUtilityPackages, | ||
); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters