-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cf7039
commit 3a6392f
Showing
6 changed files
with
229 additions
and
13 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
103 changes: 103 additions & 0 deletions
103
...ages/enzyme-matchers/src/assertions/__tests__/__snapshots__/toMatchElement--tests.js.snap
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,103 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`toMatchElement mount provides contextual information for the message 1`] = ` | ||
" | ||
actual: | ||
<Fixture> | ||
<div> | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
</div> | ||
</Fixture> | ||
expected: | ||
<Fixture> | ||
<div> | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
</div> | ||
</Fixture> | ||
" | ||
`; | ||
|
||
exports[`toMatchElement mount provides contextual information for the message 2`] = ` | ||
" | ||
actual: | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
expected: | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
" | ||
`; | ||
|
||
exports[`toMatchElement mount provides contextual information for the message 3`] = ` | ||
" | ||
actual: | ||
<Fixture> | ||
<div> | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
</div> | ||
</Fixture> | ||
expected: | ||
<div /> | ||
" | ||
`; | ||
|
||
exports[`toMatchElement mount returns the message with the proper fail verbage 1`] = `"Did not expect actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement mount returns the message with the proper fail verbage 2`] = `"Did not expect actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement mount returns the message with the proper fail verbage 3`] = `"Did not expect actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement mount returns the message with the proper pass verbage 1`] = `"Expected actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement mount returns the message with the proper pass verbage 2`] = `"Expected actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement mount returns the message with the proper pass verbage 3`] = `"Expected actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement shallow provides contextual information for the message 1`] = ` | ||
" | ||
actual: | ||
<div> | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
</div> | ||
expected: | ||
<div> | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
</div> | ||
" | ||
`; | ||
|
||
exports[`toMatchElement shallow provides contextual information for the message 2`] = ` | ||
" | ||
actual: | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
expected: | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
" | ||
`; | ||
|
||
exports[`toMatchElement shallow provides contextual information for the message 3`] = ` | ||
" | ||
actual: | ||
<div> | ||
<span id=\\"child\\" className=\\"foo\\" /> | ||
</div> | ||
expected: | ||
<div /> | ||
" | ||
`; | ||
|
||
exports[`toMatchElement shallow returns the message with the proper fail verbage 1`] = `"Did not expect actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement shallow returns the message with the proper fail verbage 2`] = `"Did not expect actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement shallow returns the message with the proper fail verbage 3`] = `"Did not expect actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement shallow returns the message with the proper pass verbage 1`] = `"Expected actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement shallow returns the message with the proper pass verbage 2`] = `"Expected actual value to match the expected value."`; | ||
|
||
exports[`toMatchElement shallow returns the message with the proper pass verbage 3`] = `"Expected actual value to match the expected value."`; |
49 changes: 49 additions & 0 deletions
49
packages/enzyme-matchers/src/assertions/__tests__/toMatchElement--tests.js
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,49 @@ | ||
const { shallow, mount } = require('enzyme'); | ||
const React = require('react'); | ||
|
||
const toMatchElement = require('../toMatchElement'); | ||
|
||
function Fixture() { | ||
return ( | ||
<div> | ||
<span id="child" className="foo" /> | ||
</div> | ||
); | ||
} | ||
|
||
describe('toMatchElement', () => { | ||
[shallow, mount].forEach(builder => { | ||
describe(builder.name, () => { | ||
const wrapper = builder(<Fixture />); | ||
const truthyResults = toMatchElement(wrapper, <Fixture />); | ||
const truthyResults2 = toMatchElement(wrapper.find('span'), | ||
<span id="child" className="foo" /> | ||
); | ||
const falsyResults = toMatchElement(wrapper, <div />); | ||
|
||
it('returns the pass flag properly', () => { | ||
expect(truthyResults.pass).toBeTruthy(); | ||
expect(truthyResults2.pass).toBeTruthy(); | ||
expect(falsyResults.pass).toBeFalsy(); | ||
}); | ||
|
||
it('returns the message with the proper pass verbage', () => { | ||
expect(truthyResults.message).toMatchSnapshot(); | ||
expect(truthyResults2.message).toMatchSnapshot(); | ||
expect(falsyResults.message).toMatchSnapshot(); | ||
}); | ||
|
||
it('returns the message with the proper fail verbage', () => { | ||
expect(truthyResults.negatedMessage).toMatchSnapshot(); | ||
expect(truthyResults2.negatedMessage).toMatchSnapshot(); | ||
expect(falsyResults.negatedMessage).toMatchSnapshot(); | ||
}); | ||
|
||
it('provides contextual information for the message', () => { | ||
expect(truthyResults.contextualInformation).toMatchSnapshot(); | ||
expect(truthyResults2.contextualInformation).toMatchSnapshot(); | ||
expect(falsyResults.contextualInformation).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
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,35 @@ | ||
/** | ||
* This source code is licensed under the MIT-style license found in the | ||
* LICENSE file in the root directory of this source tree. * | ||
* | ||
* @providesModule toMatchElementAssertion | ||
* @flow | ||
*/ | ||
|
||
import { shallow, mount } from 'enzyme'; | ||
import type { Matcher } from '../../../../types/Matcher'; | ||
import type { EnzymeObject } from '../../../../types/EnzymeObject'; | ||
import isShallowWrapper from '../utils/isShallowWrapper'; | ||
import single from '../utils/single'; | ||
|
||
function toMatchElement(actualEnzymeWrapper:EnzymeObject, reactInstance:Object) : Matcher { | ||
let expectedWrapper:EnzymeObject; | ||
if (!isShallowWrapper(actualEnzymeWrapper)) { | ||
expectedWrapper = mount(reactInstance); | ||
} else { | ||
expectedWrapper = shallow(reactInstance); | ||
} | ||
|
||
const actual = actualEnzymeWrapper.debug(); | ||
const expected = expectedWrapper.debug(); | ||
const pass = actual === expected; | ||
|
||
return { | ||
pass, | ||
message: 'Expected actual value to match the expected value.', | ||
negatedMessage: 'Did not expect actual value to match the expected value.', | ||
contextualInformation: `\nactual:\n${actual}\n\nexpected:\n${expected}\n`, | ||
}; | ||
} | ||
|
||
export default single(toMatchElement); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const SHALLOW_WRAPPER_CONSTRUCTOR = 'ShallowWrapper'; | ||
|
||
export default function isShallowWrapper(wrapper) : boolean { | ||
let isShallow; | ||
if (wrapper.constructor.name !== undefined) { | ||
isShallow = wrapper.constructor.name === SHALLOW_WRAPPER_CONSTRUCTOR; | ||
} else { | ||
isShallow = !!(`${wrapper.constructor}`).match(/^function ShallowWrapper\(/); | ||
} | ||
return isShallow; | ||
} |