1

I can't get some of the Jasmine tests for the frontend (blank and luma themes) to work.

I have generated the static files as described in the documentation.

$ bin/magento setup:static-content:deploy -f

I can e.g. run:

$ grunt spec:blank --file="dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/actions.test.js"

[...]
ui/js/grid/columns/actions
   ✓ Check getVisibleActions function
   ✓ Check addAction function
   ✓ Check isSingle and isMultiple function
   ✓ Check isActionVisible function
   ✓ Check updateActions function
   ✓ Check applyAction function
   ✓ Check getAction function

7 specs in 0.066s.
>> 0 failures

Done.
[...]

But e.g. the following two do not work:

$ grunt spec:blank --file="dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js"

[...]
 Magento_Checkout/js/sidebar
   Check remove mini-cart item callback.
     X Cart item is exists
       Uncaught TypeError: Cannot read property 'shoppingCartUrl' of undefined thrown (1)
>> Uncaught TypeError: Cannot read property 'shoppingCartUrl' of undefined thrown null
       TypeError: Cannot read property '_removeItemAfter' of undefined (2)
>> TypeError: Cannot read property '_removeItemAfter' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js:67:25)
>>     at <Jasmine>
     X Cart item doesn't exists
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot read property '_removeItemAfter' of undefined (2)
>> TypeError: Cannot read property '_removeItemAfter' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js:77:25)
>>     at <Jasmine>
     X Method "_removeItemAfter" is defined
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot read property '_removeItemAfter' of undefined (2)
>> TypeError: Cannot read property '_removeItemAfter' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js:61:32)
>>     at <Jasmine>
   Check update item quantity callback.
     X Cart item is exists
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       Error: <spyOn> : could not find an object to spy upon for _hideItemButton()
Usage: spyOn(<object>, <methodName>) (2)
>> Error: <spyOn> : could not find an object to spy upon for _hideItemButton()
>> Usage: spyOn(<object>, <methodName>) Error: <spyOn> : could not find an object to spy upon for _hideItemButton()
>> Usage: spyOn(<object>, <methodName>)
>>     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js:95:17)
>>     at <Jasmine>
     X Cart item doesn't exists
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       Error: <spyOn> : could not find an object to spy upon for _hideItemButton()
Usage: spyOn(<object>, <methodName>) (2)
>> Error: <spyOn> : could not find an object to spy upon for _hideItemButton()
>> Usage: spyOn(<object>, <methodName>) Error: <spyOn> : could not find an object to spy upon for _hideItemButton()
>> Usage: spyOn(<object>, <methodName>)
>>     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js:106:17)
>>     at <Jasmine>
     X Method "_updateItemQtyAfter" is defined
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot read property '_updateItemQtyAfter' of undefined (2)
>> TypeError: Cannot read property '_updateItemQtyAfter' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/sidebar.test.js:89:32)
>>     at <Jasmine>

6 specs in 25.22s.
>> 6 failures
Warning: Task "jasmine:blank" failed. Use --force to continue.

Aborted due to warnings.

[...]
$ grunt spec:blank --file="dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js"

[...]
 Magento_Checkout/js/view/shipping
   "showFormPopUp" method
     X Check method call.
       Uncaught TypeError: Cannot read property 'quoteData' of undefined thrown (1)
>> Uncaught TypeError: Cannot read property 'quoteData' of undefined thrown null
       TypeError: Cannot read property 'showFormPopUp' of undefined (2)
>> TypeError: Cannot read property 'showFormPopUp' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:124:28)
>>     at <Jasmine>
   "selectShippingMethod" method
     X Check method call.
       Uncaught TypeError: $.mage.__ is not a function thrown (1)
>> Uncaught TypeError: $.mage.__ is not a function thrown null
       TypeError: Cannot read property 'selectShippingMethod' of undefined (2)
>> TypeError: Cannot read property 'selectShippingMethod' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:162:28)
>>     at <Jasmine>
   "triggerShippingDataValidateEvent" method
     X Check method call.
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot set property 'source' of undefined (2)
>> TypeError: Cannot set property 'source' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:224:28)
>>     at <Jasmine>
   "setShippingInformation" method
     X Check method call.
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       Error: <spyOn> : could not find an object to spy upon for validateShippingInformation()
Usage: spyOn(<object>, <methodName>) (2)
>> Error: <spyOn> : could not find an object to spy upon for validateShippingInformation()
>> Usage: spyOn(<object>, <methodName>) Error: <spyOn> : could not find an object to spy upon for validateShippingInformation()
>> Usage: spyOn(<object>, <methodName>)
>>     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:170:17)
>>     at <Jasmine>
   "navigate" method
     X Check for return value.
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot read property 'navigate' of undefined (2)
>> TypeError: Cannot read property 'navigate' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:105:28)
>>     at <Jasmine>
   "saveNewAddress" method
     X Check method call with valid form data.
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot set property 'source' of undefined (2)
>> TypeError: Cannot set property 'source' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:143:28)
>>     at <Jasmine>
     X Check method call with invalid form data.
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot set property 'source' of undefined (2)
>> TypeError: Cannot set property 'source' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:132:28)
>>     at <Jasmine>
   "validateShippingInformation" method
     X Check method call on positive case.
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot set property 'source' of undefined (2)
>> TypeError: Cannot set property 'source' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:208:28)
>>     at <Jasmine>
     X Check method call on negative cases.
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot set property 'source' of undefined (2)
>> TypeError: Cannot set property 'source' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:190:28)
>>     at <Jasmine>
   "getPopUp" method
     X Check for return value.
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot read property 'getPopUp' of undefined (2)
>> TypeError: Cannot read property 'getPopUp' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:112:28)
>>     at <Jasmine>
     X Check on single modal call
       Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) (1)
>> Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL) Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
>>     at <Jasmine>
       TypeError: Cannot read property 'getPopUp' of undefined (2)
>> TypeError: Cannot read property 'getPopUp' of undefined     at <Jasmine>
>>     at UserContext.<anonymous> (http://localhost:8000/dev/tests/js/jasmine/tests/app/code/Magento/Checkout/frontend/js/view/shipping.test.js:117:28)
>>     at <Jasmine>

11 specs in 45.333s.
>> 11 failures
Warning: Task "jasmine:blank" failed. Use --force to continue.

Aborted due to warnings.
[...]

Are these tests broken? Do I miss something? How can I get all frontend tests to work?

It's the first time I've tried testing with Jasmine in Magento 2 at all, so I appreciate any help and advice!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.