[ https://issues.apache.org/jira/browse/AMBARI-26475?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17945804#comment-17945804 ]
Wei-Chiu Chuang commented on AMBARI-26475: ------------------------------------------ What ChatGPT expalins: The root of the problem is in the way you’ve stubbed out `Ember.run.next` inside your `#onChecked` tests. In your `beforeEach` you have: ```js sinon.stub(Em.run, 'next', function (context, callback) { callback.call(context); }); ``` That stub only works if you call it with exactly two arguments (an object and a function). Ember’s real `run.next` actually has two common signatures: 1. `Ember.run.next(function)` 2. `Ember.run.next(context, function)` In your stub, if someone ever calls `Ember.run.next(...)` with only the function form, then in your fake `context` is actually the callback and your `callback` parameter is `undefined`. You then do `callback.call(context)` and blow up with > `TypeError: Cannot read properties of undefined (reading 'call')` because `callback` is undefined. --- ### How to fix Make your stub handle *both* forms of `Ember.run.next`. For example, replace that stub with something like: ```js sinon.stub(Em.run, 'next').callsFake(function(arg1, arg2) { // if they passed only a function, call it immediately if (typeof arg1 === 'function') { arg1(); } // otherwise assume first is the context and second is the function else if (typeof arg2 === 'function') { arg2.call(arg1); } }); ``` so that: - `Ember.run.next(fn)` → immediately calls `fn()`, and - `Ember.run.next(ctx, fn)` → immediately calls `fn.call(ctx)`. Once you make that change, your `view.propertyDidChange('checked')` will correctly invoke your `onChecked` hook (or skip it, in the “not invoked with click” case) without ever hitting an undefined `callback`. --- #### Updated snippet in your test ```js describe('#onChecked', function () { beforeEach(function () { // stub run.next to handle both signatures sinon.stub(Em.run, 'next').callsFake(function(arg1, arg2) { if (typeof arg1 === 'function') { arg1(); } else if (typeof arg2 === 'function') { arg2.call(arg1); } }); sinon.stub(view, 'sendRequestRorDependentConfigs', Em.K); sinon.stub(view, 'updateForeignKeys', Em.K); sinon.stub(view, 'updateCheck', Em.K); view.setProperties({ clicked: item.clicked, 'parentView.serviceConfig.value': 'v0', value: 'v1' }); view.propertyDidChange('checked'); }); afterEach(function () { Em.run.next.restore(); view.sendRequestRorDependentConfigs.restore(); view.updateForeignKeys.restore(); view.updateCheck.restore(); }); // … your it() blocks … }); ``` With that in place your stub no longer crashes when `run.next` is invoked in either of its two forms, and your assertions for `"invoked with click"` vs `"not invoked with click"` should start passing again. > Two Ambari WebUI Tests failures > ------------------------------- > > Key: AMBARI-26475 > URL: https://issues.apache.org/jira/browse/AMBARI-26475 > Project: Ambari > Issue Type: Bug > Affects Versions: 3.1.0 > Reporter: Wei-Chiu Chuang > Priority: Major > > I disabled python tests and still I'm getting two web test failures > https://ci-hadoop.apache.org/job/Ambari/job/Ambari-PreCommit-GitHub-PR/job/PR-3998/3/consoleFull > {noformat} > HeadlessChrome 0.0.0 (Linux 0.0.0) Ambari Web Unit tests > test/views/common/controls_view_test App.ServiceConfigRadioButton #onChecked > invoked with click "before each" hook for "property value" FAILED > TypeError: Cannot read properties of undefined (reading 'call') > at Ember.run.<anonymous> > (test/views/common/controls_view_test.js:533:22) > at proxy.invoke (node_modules/sinon/pkg/sinon.js:1394:55) > at Ember.run.proxy [as next] (eval at createProxy > (node_modules/sinon/pkg/sinon.js:1318:13), <anonymous>:1:37) > at Class.checkedChanged (vendor/scripts/ember-latest.js:19942:15) > at invokeAction (vendor/scripts/ember-latest.js:3174:12) > at iterateSet (vendor/scripts/ember-latest.js:3156:15) > at Object.sendEvent (vendor/scripts/ember-latest.js:3273:3) > at notifyObservers (vendor/scripts/ember-latest.js:1865:11) > at Ember.notifyObservers (vendor/scripts/ember-latest.js:1980:3) > at Object.propertyDidChange (vendor/scripts/ember-latest.js:2613:9) > HeadlessChrome 0.0.0 (Linux 0.0.0): Executed 20551 of 22912 (1 FAILED) > (skipped 541) (0 secs / 4.425 secs) > HeadlessChrome 0.0.0 (Linux 0.0.0) Ambari Web Unit tests > test/views/common/controls_view_test App.ServiceConfigRadioButton #onChecked > not invoked with click "before each" hook for "property value" FAILED > TypeError: Cannot read properties of undefined (reading 'call') > at Ember.run.<anonymous> > (test/views/common/controls_view_test.js:533:22) > at proxy.invoke (node_modules/sinon/pkg/sinon.js:1394:55) > at Ember.run.proxy [as next] (eval at createProxy > (node_modules/sinon/pkg/sinon.js:1318:13), <anonymous>:1:37) > at Class.checkedChanged (vendor/scripts/ember-latest.js:19942:15) > at invokeAction (vendor/scripts/ember-latest.js:3174:12) > at iterateSet (vendor/scripts/ember-latest.js:3156:15) > at Object.sendEvent (vendor/scripts/ember-latest.js:3273:3) > at notifyObservers (vendor/scripts/ember-latest.js:1865:11) > at Ember.notifyObservers (vendor/scripts/ember-latest.js:1980:3) > at Object.propertyDidChange (vendor/scripts/ember-latest.js:2613:9) > {noformat} -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ambari.apache.org For additional commands, e-mail: issues-h...@ambari.apache.org