Skip to content
This repository was archived by the owner on Mar 21, 2020. It is now read-only.

Commit 09b496f

Browse files
authored
Merge pull request #65 from khoanguyen96/fix-deprecation-matchMedia-test
Fix deprecation notices and match media failure in tests
2 parents c77ab2e + 938cf3b commit 09b496f

File tree

7 files changed

+64
-51
lines changed

7 files changed

+64
-51
lines changed

test/unit/jest.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path');
22

33
module.exports = {
4+
testURL: 'http://localhost',
45
rootDir: path.resolve(__dirname, '../../'),
56
moduleFileExtensions: [
67
'js',

test/unit/setup.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import Vue from 'vue';
22

33
Vue.config.productionTip = false;
44

5-
global.jsdom.reconfigure({
6-
url: 'http://localhost',
7-
});
5+
// polyfill matchMedia
6+
window.matchMedia = window.matchMedia ||
7+
(() => ({
8+
matches: false,
9+
addListener: () => {},
10+
removeListener: () => {},
11+
}));

test/unit/specs/components/PayPalCheckout.spec.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createLocalVue, shallow } from '@vue/test-utils';
1+
import { createLocalVue, shallowMount } from '@vue/test-utils';
22
import { createRenderer } from 'vue-server-renderer';
33
import PayPalCheckout from '@/components/PayPalCheckout.vue';
44

@@ -40,58 +40,62 @@ function getProps() {
4040
}
4141

4242
describe('PayPalCheckout.vue', () => {
43-
const localVue = createLocalVue();
44-
const checkout = shallow(PayPalCheckout, {
45-
attachToDocument: true,
46-
propsData: getProps(),
47-
localVue,
43+
let checkout;
44+
45+
beforeEach(() => {
46+
const localVue = createLocalVue();
47+
checkout = shallowMount(PayPalCheckout, {
48+
attachToDocument: true,
49+
propsData: getProps(),
50+
localVue,
51+
});
4852
});
4953

50-
it('should have the amount prop', () => {
54+
test('should have the amount prop', () => {
5155
expect(checkout.props().amount).toEqual('30.00');
5256
});
5357

54-
it('should have the client prop with production and sandbox', () => {
58+
test('should have the client prop with production and sandbox', () => {
5559
expect(checkout.vm.client).toEqual(credentials);
5660
});
5761

58-
it('should have the currency prop', () => {
62+
test('should have the currency prop', () => {
5963
expect(checkout.vm).toEqual(expect.objectContaining({
6064
currency: expect.any(String),
6165
}));
6266
expect(checkout.vm.currency.length).toBeGreaterThan(2);
6367
});
6468

65-
it('should have the commit prop', () => {
69+
test('should have the commit prop', () => {
6670
expect(checkout.props().commit).toBe(true);
6771
});
6872

69-
it('should have the env prop', () => {
73+
test('should have the env prop', () => {
7074
expect(checkout.props().env).toBeTruthy();
7175
});
7276

73-
it('should have the invoiceNumber prop', () => {
77+
test('should have the invoiceNumber prop', () => {
7478
expect(checkout.props().invoiceNumber).toEqual('201705051001');
7579
});
7680

77-
it('should have the items prop', () => {
81+
test('should have the items prop', () => {
7882
expect(checkout.vm).toEqual(expect.objectContaining({
7983
items: expect.any(Array),
8084
}));
8185
});
8286

8387
// TODO: renable after jsdom fixes css parsing
8488
describe('iframe rendering', () => {
85-
it('div', () => {
89+
test('div', () => {
8690
const div = checkout.find('div');
8791
expect(div.is('div')).toBe(true);
8892
});
8993

90-
it('has xcomponent class', () => {
94+
test('has xcomponent class', () => {
9195
expect(checkout.contains('.xcomponent-visible')).toBe(true);
9296
});
9397

94-
it('has same HTML structure', () => {
98+
test('has same HTML structure', () => {
9599
const renderer = createRenderer();
96100
renderer.renderToString(checkout.vm, (err, str) => {
97101
if (err) throw new Error(err);

test/unit/specs/components/SimpleMethods.spec.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createLocalVue, shallow } from '@vue/test-utils';
1+
import { createLocalVue, shallowMount } from '@vue/test-utils';
22
import PayPalCheckout from '@/components/PayPalCheckout.vue';
33

44
const credentials = {
@@ -54,52 +54,56 @@ jest.mock('paypal-checkout', () => ({
5454
}));
5555

5656
describe('Methods within PayPalCheckout.vue', () => {
57-
const localVue = createLocalVue();
58-
const checkout = shallow(PayPalCheckout, {
59-
localVue,
60-
attachToDocument: true,
61-
propsData: getProps(),
57+
let checkout;
58+
59+
beforeEach(() => {
60+
const localVue = createLocalVue();
61+
checkout = shallowMount(PayPalCheckout, {
62+
localVue,
63+
attachToDocument: true,
64+
propsData: getProps(),
65+
});
6266
});
6367

6468
describe('Environment', () => {
65-
it('env prop is true', () => {
69+
test('env prop is true', () => {
6670
expect(checkout.props().env).toEqual('sandbox');
6771
});
6872
});
6973

7074
describe('vue.payment()', () => {
71-
it('has payment()', () => {
75+
test('has payment()', () => {
7276
expect(checkout.vm).toEqual(expect.objectContaining({
7377
payment: expect.any(Function),
7478
}));
7579
});
7680

77-
it('returns a payment object', () => (
81+
test('returns a payment object', () => (
7882
checkout.vm.payment().then((p) => {
7983
expect(p).toBeInstanceOf(Object);
8084
})
8185
));
8286

83-
it('payment object has experience object', () => {
87+
test('payment object has experience object', () => {
8488
checkout.vm.payment().then((p) => {
8589
expect(p.experience).toEqual(checkout.vm.experience);
8690
});
8791
});
8892

89-
it('payment object has transactions array', () => (
93+
test('payment object has transactions array', () => (
9094
checkout.vm.payment().then((p) => {
9195
expect(p.payment).toEqual(expect.objectContaining({
9296
transactions: expect.any(Array),
9397
}));
9498
})));
9599

96-
it('payment object has one single transaction', () => (
100+
test('payment object has one single transaction', () => (
97101
checkout.vm.payment().then((p) => {
98102
expect(p.payment.transactions.length).toBe(1);
99103
})
100104
));
101105

102-
it('transaction has the right amount', () => (
106+
test('transaction has the right amount', () => (
103107
checkout.vm.payment().then((p) => {
104108
const transaction = p.payment.transactions[0];
105109
expect(transaction.amount).toEqual(expect.objectContaining({
@@ -109,7 +113,7 @@ describe('Methods within PayPalCheckout.vue', () => {
109113
})
110114
));
111115

112-
it('transaction has the right currency', () => (
116+
test('transaction has the right currency', () => (
113117
checkout.vm.payment().then((p) => {
114118
const transaction = p.payment.transactions[0];
115119
expect(transaction.amount).toEqual(expect.objectContaining({
@@ -119,7 +123,7 @@ describe('Methods within PayPalCheckout.vue', () => {
119123
})
120124
));
121125

122-
it('transaction has the right invoice number', () => (
126+
test('transaction has the right invoice number', () => (
123127
checkout.vm.payment().then((p) => {
124128
const transaction = p.payment.transactions[0];
125129
expect(transaction).toEqual(expect.objectContaining({
@@ -129,7 +133,7 @@ describe('Methods within PayPalCheckout.vue', () => {
129133
})
130134
));
131135

132-
it('transaction has a item_list', () => (
136+
test('transaction has a item_list', () => (
133137
checkout.vm.payment().then((p) => {
134138
const transaction = p.payment.transactions[0];
135139
expect(transaction).toEqual(expect.objectContaining({
@@ -138,7 +142,7 @@ describe('Methods within PayPalCheckout.vue', () => {
138142
})
139143
));
140144

141-
it('transaction has items array', () => (
145+
test('transaction has items array', () => (
142146
checkout.vm.payment().then((p) => {
143147
const itemList = p.payment.transactions[0].item_list;
144148
expect(itemList).toEqual(expect.objectContaining({
@@ -150,16 +154,16 @@ describe('Methods within PayPalCheckout.vue', () => {
150154
});
151155

152156
describe('action methods', () => {
153-
it('has onAuthorize() and onCancel()', () => {
157+
test('has onAuthorize() and onCancel()', () => {
154158
expect(checkout.vm).toEqual(expect.objectContaining({
155159
onAuthorize: expect.any(Function),
156160
onCancel: expect.any(Function),
157161
}));
158162
});
159163

160-
it('onAuthorize() returns true and not a promise if commit is false', () => {
161-
const component = shallow(PayPalCheckout, {
162-
localVue,
164+
test('onAuthorize() returns true and not a promise if commit is false', () => {
165+
const component = shallowMount(PayPalCheckout, {
166+
localVue: createLocalVue(),
163167
attachToDocument: true,
164168
propsData: { ...getProps(), commit: false },
165169
});

test/unit/specs/util/additionalProps.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import additionalProps from '@/util/additionalProps';
22

33
describe('additionalProps.js', () => {
4-
it('exports two functions', () => {
4+
test('exports two functions', () => {
55
expect(additionalProps).toEqual(expect.objectContaining({
66
vmProps: expect.any(Function),
77
getTypedProps: expect.any(Function),
88
}));
99
});
1010

11-
it('has the button props', () => {
11+
test('has the button props', () => {
1212
const props = additionalProps.vmProps();
1313

1414
expect(props).toEqual(expect.objectContaining({
@@ -39,7 +39,7 @@ describe('additionalProps.js', () => {
3939
}));
4040
});
4141

42-
it('has the payment(s) props', () => {
42+
test('has the payment(s) props', () => {
4343
const props = additionalProps.vmProps();
4444

4545
expect(props).toEqual(expect.objectContaining({
@@ -54,7 +54,7 @@ describe('additionalProps.js', () => {
5454
}));
5555
});
5656

57-
it('has the transaction props', () => {
57+
test('has the transaction props', () => {
5858
const props = additionalProps.vmProps();
5959

6060
expect(props).toEqual(expect.objectContaining({

test/unit/specs/util/defaultProps.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import defaultProps from '@/util/defaultProps';
22

33
describe('defaultProps.js', () => {
4-
it('has the required props', () => {
4+
test('has the required props', () => {
55
const props = defaultProps();
66

77
expect(props).toEqual(expect.objectContaining({
@@ -21,7 +21,7 @@ describe('defaultProps.js', () => {
2121
});
2222
});
2323

24-
it('has the optional props', () => {
24+
test('has the optional props', () => {
2525
const props = defaultProps();
2626

2727
expect(props).toEqual(expect.objectContaining({
@@ -40,7 +40,7 @@ describe('defaultProps.js', () => {
4040
});
4141
});
4242

43-
it('has the specific props', () => {
43+
test('has the specific props', () => {
4444
const props = defaultProps();
4545

4646
expect(props).toEqual(expect.objectContaining({

test/unit/specs/util/paypalProp.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PayPalProp from '@/util/paypalProp';
22

33
describe('paypalProp.js', () => {
44
describe('new paypalProp()', () => {
5-
it('construct with most options specified', () => {
5+
test('construct with most options specified', () => {
66
const paypal = new PayPalProp({
77
name: 'some-name',
88
paypalName: 'somePaypal',
@@ -16,7 +16,7 @@ describe('paypalProp.js', () => {
1616
}));
1717
});
1818

19-
it('construct with just name specified', () => {
19+
test('construct with just name specified', () => {
2020
const paypal = new PayPalProp({ name: 'some-name' });
2121

2222
expect(paypal).toEqual(expect.objectContaining({
@@ -27,7 +27,7 @@ describe('paypalProp.js', () => {
2727
});
2828
});
2929

30-
it('getVmProp()', () => {
30+
test('getVmProp()', () => {
3131
const paypal = new PayPalProp({
3232
name: 'some-name',
3333
paypalName: 'somePaypal',
@@ -42,7 +42,7 @@ describe('paypalProp.js', () => {
4242
});
4343
});
4444

45-
it('change()', () => {
45+
test('change()', () => {
4646
const paypal = new PayPalProp({
4747
name: 'some-name',
4848
paypalName: 'somePaypal',

0 commit comments

Comments
 (0)