small medium large xlarge

12 Nov 2016, 16:27
Ryan Pool (14 posts)

I will include my CustomerSearchComponent.spec.js in a followup so it’s not all mashed together but in all three of my back end failure tests it looks like CustomerSearchComponent can not see the stubbed window.alert.

1) CustomerSearchComponent search A search for ‘pat’, three or more characters A search that fails on the back-end sets the keywords to be ‘pat’ Message: ReferenceError: alert is not defined Stacktrace: ReferenceError: alert is not defined at Array. (/shine/webpack/CustomerSearchComponent.js:65:17) at /shine/node_modules/testdouble/lib/store/stubbings.js:83:28 at arrayEach (/shine/node_modules/testdouble/node_modules/lodash/index.js:1289:13) at Function. (/shine/node_modules/testdouble/node_modules/lodash/index.js:3345:13) at invokeCallbackFor (/shine/node_modules/testdouble/lib/store/stubbings.js:77:14) at executePlan (/shine/node_modules/testdouble/lib/store/stubbings.js:51:5) at Object.invoke (/shine/node_modules/testdouble/lib/store/stubbings.js:33:14) at Object.testDouble [as subscribe] (/shine/node_modules/testdouble/lib/function.js:37:24) at search (/shine/webpack/CustomerSearchComponent.js:60:11) at . (/shine/spec/javascripts/CustomerSearchComponent.spec.js:92:31)

12 Nov 2016, 16:36
Ryan Pool (14 posts)

Instead of including the spec here I created a gist.



13 Nov 2016, 15:20
David Copeland (511 posts)

It’s hard to tell what problem you are having from the output you pasted. It looks like alert isn’t defined? Are you calling it on window?

It looks like the sample code might be out of date. In application.js instead of calling alert(..);, you need to call window.alert(..);. The window test double you are creating will make that work in your unit test.

13 Nov 2016, 17:18
Ryan Pool (14 posts)

Changing alert(response) to window.alert(response) in webpack/CustomerSearchComponent.js fixed my failing tests.

Thank you.

You must be logged in to comment