Skip to content

Commit f22ead8

Browse files
committed
Refactor test with .find() undefined method of js prototype
1 parent 08996db commit f22ead8

File tree

1 file changed

+54
-6
lines changed
  • dev/tests/js/jasmine/tests/app/code/Magento/ConfigurableProduct/view/frontend/js

1 file changed

+54
-6
lines changed

dev/tests/js/jasmine/tests/app/code/Magento/ConfigurableProduct/view/frontend/js/configurable.test.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,63 @@ define([
2020
selectElement = $(option);
2121

2222
beforeEach(function () {
23+
//remove this lines when jasmine version will be upgraded
24+
if (!Array.prototype.find) {
25+
Object.defineProperty(Array.prototype, 'find', {//eslint-disable-line
26+
enumerable: false,
27+
configurable: true,
28+
writable: true,
29+
30+
/**
31+
* Find method
32+
*/
33+
value: function (predicate) {
34+
var list = Object(this),
35+
length = list.length >>> 0,
36+
thisArg = arguments[1],
37+
value,
38+
i;
39+
40+
if (this == null) {
41+
throw new TypeError('Array.prototype.find called on null or undefined');
42+
}
43+
44+
if (typeof predicate !== 'function') {
45+
throw new TypeError('predicate must be a function');
46+
}
47+
48+
for (i = 0; i < length; i++) {
49+
if (i in list) {
50+
value = list[i];
51+
52+
if (predicate.call(thisArg, value, i, list)) {//eslint-disable-line
53+
return value;
54+
}
55+
}
56+
}
57+
58+
return undefined;
59+
}
60+
});
61+
}
2362
widget = new Configurable();
2463
widget.options = {
2564
spConfig: {
2665
chooseText: 'Chose an Option...',
2766
attributes:
2867
{
2968
'size': {
30-
options: $('<div><p class="2"></p></div>')
69+
options: [
70+
{
71+
id: '2',
72+
value: '2'
73+
},
74+
{
75+
id: 3,
76+
value: 'red'
77+
78+
}
79+
]
3180
}
3281
},
3382
prices: {
@@ -45,16 +94,15 @@ define([
4594

4695
it('check if attribute value is possible to be set as configurable option', function () {
4796
expect($.mage.configurable).toBeDefined();
48-
widget._parseQueryParams('http://magento.com/product?color=red&size=2');
97+
widget._parseQueryParams('size=2');
4998
expect(widget.options.values.size).toBe('2');
5099
});
51100

52-
it('check if attribute value is possible to be set as option with "please select option"', function () {
101+
it('check that attribute value is not set id provided option does not exists', function () {
53102
expect($.mage.configurable).toBeDefined();
103+
widget._parseQueryParams('size=10');
54104
widget._fillSelect(selectElement[0]);
55-
expect(selectElement[0].options[0].innerHTML).toBe(widget.options.spConfig.chooseText);
56-
widget._parseQueryParams('http://magento.com/product?color=red&size=2');
57-
expect(widget.options.values.size).toBe('2');
105+
expect(widget.options.values.size).toBe(undefined);
58106
});
59107
});
60108
});

0 commit comments

Comments
 (0)