Skip to content

Commit 9a514d1

Browse files
author
Arron Fletcher
authored
[0.12.8] Replace moment.js with date-fns (#52)
* added date-fns to package * ripped moment out of order-list.js * [WIP] replacing moment * all tests passing * bumpped version to 0.12.8 * clean up * now grabbing date functions individually * changed approach to mocking dates. Tests now passing * refactor businessDaysFromNow function
1 parent 345a778 commit 9a514d1

File tree

13 files changed

+3170
-6661
lines changed

13 files changed

+3170
-6661
lines changed

__tests__/components/checkout/__snapshots__/shipping-methods.spec.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ exports[`renders error messages 1`] = `
173173
<span
174174
className="c-shipping-method__list-delivery-date"
175175
>
176-
Wednesday 15th May
176+
Wednesday 22nd May
177177
</span>
178178
</label>
179179
</div>
@@ -218,7 +218,7 @@ exports[`renders error messages 1`] = `
218218
<span
219219
className="c-shipping-method__list-delivery-date"
220220
>
221-
Thursday 16th May
221+
Thursday 23rd May
222222
</span>
223223
</label>
224224
</div>
@@ -263,7 +263,7 @@ exports[`renders error messages 1`] = `
263263
<span
264264
className="c-shipping-method__list-delivery-date"
265265
>
266-
Wednesday 15th May
266+
Wednesday 22nd May
267267
</span>
268268
</label>
269269
</div>
@@ -308,7 +308,7 @@ exports[`renders error messages 1`] = `
308308
<span
309309
className="c-shipping-method__list-delivery-date"
310310
>
311-
Thursday 16th May
311+
Thursday 23rd May
312312
</span>
313313
</label>
314314
</div>

__tests__/components/checkout/shipping-methods.spec.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Libraries
22
import React from 'react'
3+
import MockDate from 'mockdate'
34

45
// Components
56
import ShippingMethods from '../../../src/components/checkout/shipping-methods'
@@ -13,20 +14,10 @@ import shippingMethodsFixture from '../../fixtures/shipping-methods'
1314

1415
describe('ShippingMethods', () => {
1516
// Setup mock date for testing business days
16-
const RealDate = Date
17-
const mockDate = new Date('2019-01-01')
18-
19-
beforeAll(() => {
20-
global.Date = class extends Date {
21-
constructor () {
22-
super()
23-
return mockDate
24-
}
25-
}
26-
})
17+
MockDate.set('5/20/2019')
2718

2819
afterAll(() => {
29-
global.Date = RealDate
20+
MockDate.reset()
3021
})
3122

3223
test('renders a nothing when shipping methods are loading', () => {
@@ -57,7 +48,7 @@ describe('ShippingMethods', () => {
5748
expect(wrapper.find('div').first()).toHaveClassName(mockClassName)
5849
expect(wrapper).toIncludeText(shippingMethodsFixture[0].label)
5950
// Check for estimated delivery
60-
expect(wrapper).toIncludeText('Wednesday 9th January')
51+
expect(wrapper).toIncludeText('Tuesday 21st May')
6152

6253
// Get the last shipping method in the fixture
6354
const lastShippingMethodFixture = shippingMethodsFixture[shippingMethodsFixture.length - 1]

__tests__/components/orders/order-list.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Libraries
22
import React from 'react'
3-
import moment from 'moment-business-days'
4-
5-
moment.locale('en-gb')
3+
import format from 'date-fns/format'
64

75
// Component
86
import OrderList from '../../../src/components/orders/order-list'
@@ -24,7 +22,7 @@ test('renders correctly', () => {
2422
const order = orders.data[0]
2523
const shippingTotal = instance.renderShippingTotal(order)
2624
const orderTotal = penceToPounds(order.pricing.total_inc_tax)
27-
const orderDate = moment(new Date(order.placed_at)).format('MMM D, YYYY')
25+
const orderDate = format(new Date(order.placed_at), 'MMM D, YYYY')
2826

2927
// Assert
3028
expect(wrapper).toMatchSnapshot()

__tests__/components/products/listing/product-listing-card.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import productSearchHit from '../../../fixtures/product-search-hit'
1010
test('renders ProductListingCard correctly', () => {
1111
// Act
1212

13-
// at the moment we dont pass the image size throught algolia,
14-
// the fixture will need updating when we do. At the moment
15-
// product listing is set to default to 280
13+
// Currently we dont pass the image size through algolia,
14+
// the fixture will need updating when we do. Currently,
15+
// product listing is set to default to 280.
1616

1717
const wrapper = mount(
1818
<ProductListingCard

0 commit comments

Comments
 (0)