-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React unit testing example #2170
Merged
Merged
Changes from 9 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
af9fc5e
component snapshot
joykare 6fa0cc6
babel additions
joykare 49c3335
remove dependancies not used
joykare e1472f7
Use mocks to mock input props for component
joykare baad7fe
Merge branch 'development' into joykare-testing-2066
joykare 6c5b725
Change stored snapshot to match new look after merge with development
joykare 65fb97b
replace babel-latest with babel-es2015
joykare c96c7a2
Take care of warning
joykare 5255cb0
babelrc to es2015
joykare a3cef62
Merge branch 'development' into joykare-testing-2066
brent-hoover 4caa827
Add back in missing babel package
brent-hoover 433b1e7
no more globals!
jshimko b8bbb23
Declare variable before assigning
brent-hoover 0092774
Declare variable before assigning
brent-hoover 76942d3
Declare variable before assigning. Remove unused variables
brent-hoover 5ce8d55
Remove unused variable, check
brent-hoover 0de146c
Merge branch 'development' into joykare-testing-2066
brent-hoover 789dfc9
Declare variable before using it
brent-hoover 06e0bb1
Declare variable before using it
brent-hoover 6221221
Can't use `this` in an arrow function
brent-hoover 882fd7d
Correct function declarations
brent-hoover 1d38e3f
Eliminate implied global `Alerts` + no undeclared
brent-hoover 5b947a5
Remove commented out code
brent-hoover e305df1
Declare explicit globals
brent-hoover da994a7
move default userCurrency deeper in the object (#2259)
kieckhafer 1d3b551
Merge branch 'development' into joykare-testing-2066
brent-hoover 24b36b7
Use Collection explicit functions
brent-hoover 2779dfd
Don't log doing nothing
brent-hoover a5dbd5d
Make Alert a global because it's a mess
brent-hoover 3c7daf7
Ok actually, don't do that
brent-hoover 63cb3b3
Don't allow implicit globals
brent-hoover a557e37
Bug fixes
brent-hoover adaaf3f
Fixing lack of declaration
brent-hoover 3e0a5c1
Pass error to logger
brent-hoover 0963556
Merge branch 'development' into joykare-testing-2066
952be34
Fix import order
brent-hoover b841ead
Fix changed reference
brent-hoover 4d6f0c6
Add jest testing to Circle CI
brent-hoover 8a9e765
Update NPM packages
brent-hoover 826e596
Added npm test command
mikemurray 0fa6639
Use an NPM script rather than global Jest
brent-hoover 18579f9
Merge branch 'development' into joykare-testing-2066
brent-hoover 6a6c2af
Merge development
a230696
remove circle.yml
f54f155
Make changes to new CI config
brent-hoover c7b1873
Change to proper step configuration
brent-hoover fc38b24
For clarity, `test-react`
f8eaa7f
Revert "For clarity, `test-react`"
7c312de
Merge branch 'development' into joykare-testing-2066
8eaaa19
Update Jest to current version
brent-hoover 7a3824a
Merge branch 'development' into joykare-testing-2066
brent-hoover 07f82eb
Just testing to see if this fixes it
brent-hoover 19b7528
Remove npm install of desperation
brent-hoover 43d0f61
Remove node cache
brent-hoover eb1bdca
Merge branch 'development' into joykare-testing-2066
9fb1797
Merge branch 'development' into joykare-testing-2066
mikemurray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"plugins": ["lodash"], | ||
"presets": ["stage-2"] | ||
"presets": ["es2015", "react", "stage-2"] | ||
} |
187 changes: 187 additions & 0 deletions
187
...s/plugins/core/orders/client/__tests__/components/__snapshots__/orderSummary.spec.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,187 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`OrderSummary snapshot test 1`] = ` | ||
<div> | ||
<div | ||
className="order-summary-form-group bg-info" | ||
style={ | ||
Object { | ||
"lineHeight": 3, | ||
"marginLeft": -15, | ||
"marginRight": -15, | ||
"marginTop": -15, | ||
} | ||
} | ||
> | ||
<strong | ||
style={ | ||
Object { | ||
"marginLeft": 15, | ||
} | ||
} | ||
/> | ||
, | ||
<div | ||
className="invoice-details" | ||
style={ | ||
Object { | ||
"marginRight": 15, | ||
} | ||
} | ||
> | ||
<strong> | ||
ID | ||
</strong> | ||
</div> | ||
</div> | ||
<div | ||
className="roll-up-invoice-list" | ||
> | ||
<div | ||
className="roll-up-content" | ||
> | ||
<div | ||
style={ | ||
Object { | ||
"marginBottom": 4, | ||
} | ||
} | ||
> | ||
<span | ||
className="badge badge-undefined" | ||
/> | ||
</div> | ||
<div | ||
className="order-summary-form-group" | ||
> | ||
<strong | ||
data-i18n="order.created" | ||
> | ||
Created | ||
</strong> | ||
<div | ||
className="invoice-details" | ||
/> | ||
</div> | ||
<div | ||
className="order-summary-form-group" | ||
> | ||
<strong | ||
data-i18n="order.processor" | ||
> | ||
Processor | ||
</strong> | ||
<div | ||
className="invoice-details" | ||
/> | ||
</div> | ||
<div | ||
className="order-summary-form-group" | ||
> | ||
<strong | ||
data-i18n="order.payment" | ||
> | ||
Payment | ||
</strong> | ||
<div | ||
className="invoice-details" | ||
> | ||
( | ||
) | ||
</div> | ||
</div> | ||
<div | ||
className="order-summary-form-group" | ||
> | ||
<strong | ||
data-i18n="order.transaction" | ||
> | ||
Transaction | ||
</strong> | ||
<div | ||
className="invoice-details" | ||
/> | ||
</div> | ||
<div | ||
className="order-summary-form-group" | ||
> | ||
<strong | ||
data-i18n="orderShipping.carrier" | ||
> | ||
Carrier | ||
</strong> | ||
<div | ||
className="invoice-details" | ||
> | ||
- | ||
</div> | ||
</div> | ||
<div | ||
className="order-summary-form-group" | ||
> | ||
<strong | ||
data-i18n="orderShipping.tracking" | ||
> | ||
Tracking | ||
</strong> | ||
<div | ||
className="invoice-details" | ||
/> | ||
</div> | ||
<div | ||
className="order-summary-form-group" | ||
> | ||
<strong | ||
data-i18n="orderShipping.printLabels" | ||
> | ||
Labels | ||
</strong> | ||
<a | ||
className="invoice-details" | ||
target="_blank" | ||
> | ||
<span | ||
data-i18n="orderShipping.printCustomsLabel" | ||
> | ||
Print Customs | ||
</span> | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
<br /> | ||
<div | ||
className="order-summary-form-group" | ||
> | ||
<strong | ||
data-i18n="orderShipping.shipTo" | ||
> | ||
Ship to | ||
</strong> | ||
<div | ||
className="invoice-details" | ||
> | ||
<strong> | ||
Phone: | ||
</strong> | ||
</div> | ||
</div> | ||
<div | ||
style={ | ||
Object { | ||
"marginTop": 4, | ||
} | ||
} | ||
> | ||
<span /> | ||
<br /> | ||
<span /> | ||
<br /> | ||
<span> | ||
, | ||
, | ||
|
||
</span> | ||
</div> | ||
</div> | ||
`; |
47 changes: 47 additions & 0 deletions
47
imports/plugins/core/orders/client/__tests__/components/orderSummary.spec.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,47 @@ | ||
import React from "react"; | ||
import OrderSummary from "../../components/orderSummary"; | ||
import { shallow } from "enzyme"; | ||
import shallowToJSON from "enzyme-to-json"; | ||
|
||
/** | ||
* Order Summary is a display only component | ||
* It receives props and displays them accordingly | ||
*/ | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
/** | ||
* Snapshots make sure your UI does not change unexpectedly | ||
*/ | ||
|
||
test("OrderSummary snapshot test", () => { | ||
// Initializing all the props passed into order summary component | ||
const dateFormat = jest.fn(); | ||
const tracking = jest.fn(); | ||
const shipmentStatus = jest.fn(()=>({})); | ||
const printableLabels = jest.fn(()=>({})); | ||
const profile = {}; | ||
const order = { | ||
shipping: [{ shipmentMethod: {} }], | ||
billing: [ | ||
{ paymentMethod: {}, | ||
invoice: {} | ||
} | ||
] | ||
}; | ||
|
||
const component = shallow( | ||
<OrderSummary | ||
dateFormat={dateFormat} | ||
tracking={tracking} | ||
profile={profile} | ||
shipmentStatus={shipmentStatus} | ||
printableLabels={printableLabels} | ||
order={order} | ||
/> | ||
); | ||
const tree = shallowToJSON(component); | ||
expect(tree).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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is being used above - it probably still needs to be included or babel will be upset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, yeah... that's not gonna work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this change. No difference.