Search code examples
extjssencha-testsencha-test-2.1

Error using hasCls within an expect in Sencha Test


Sencha Test 2.1

Is there a bug regarding the use of hasCls within an expect?

Lets say I have something like:

this.component().gotoButton('[text=See]').gotoComponent('menucheckitem[text=some text]')
            .and(function (el) {
                el.hasCls('x-menu-item-checked'); //this works correctly, validates the el has the class and returns a timeout if the el doesn't actually have the class
                expect(el.hasCls('x-menu-item-checked')).toBe(true); // but doing this throws a nasty error, see the detail below
        });

(although in this case it's a component not an element same thing happens with elements)

So I've tried referencing different elements and always that I try to do:

expect(el.hasClass('some')).toBe(true);

I get this error, wonder if I'm missing something or this is a bug.

I see in the docs that this should be possible. http://docs.sencha.com/sencha_test/2.1.0/api/ST.future.Element.html?#method-and

Expected constructor({ context: constructor({ breakOnFailure: false, evaluateTestsOnReady: true, eventDelay: 500, eventTranslation: true, failOnMultipleMatches: true, globals: Object({ speechSynthesis: true, caches: true, localStorage: true, sessionStorage: true, webkitStorageInfo: true, indexedDB: true, webkitIndexedDB: true, ondeviceorientationabsolute: true, ondeviceorientation: true, ondevicemotion: true, crypto: true, postMessage: true, blur: true, focus: true, close: true, stop: true, open: true, alert: true, applicationCache: true, performance: true, confirm: true, onunload: true, onunhandledrejection: true, onstorage: true, prompt: true, onrejectionhandled: true, onpopstate: true, onpageshow: true, print: true, onpagehide: true, ononline: true, onoffline: true, requestAnimationFrame: true, onmessage: true, onlanguagechange: true, onhashchange: true, cancelAnimationFrame: true, onbeforeunload: true, onwaiting: true, onvolumechange: true, captureEvents: true, ontoggle: true, ontimeupdate: true, onsuspend: true, releaseEvents: true, onsubmit: true, onstalled: true, onshow: true, getComputedStyle: true, onselect: true, onseeking: true, onseeked: true, matchMedia: true, onscroll: true, onresize: true, moveTo: true, onreset: true, onratechange: true, onprogress: true, moveBy: true, onplaying: true, onplay: true, onpause: true, onmousewheel: true, resizeTo: true, onmouseup: true, onmouseover: true, resizeBy: true, onmouseout: true, onmousemove: true, onmouseleave: true, onmouseenter: true, getSelection: true, onmousedown: true, onloadstart: true, onloadedmetadata: true, find: true, onloadeddata: true, onload: true, getMatchedCSSRules: true, onkeyup: true, onkeypress: true, onkeydown: true, webkitRequestAnimationFrame: true, oninvalid: true, oninput: true, onfocus: true, onerror: true, webkitCancelAnimationFrame: true, onended: true, onemptied: true, webkitCancelRequestAnimationFrame: true, onduratio ...


Solution

  • For an in-browser scenario, yes, this should definitely work. However, I suspect that you are using a WebDriver-based scenario. In these scenario types, the argument passed to the and() is not the component or element instance (since you'll never have access to those in the spec of a WebDriver-based scenario), but rather the future itself:

    Per the docs for and(): "If the scenario is a WebDriver scenario the arg will >be the current future"

    So in this example, your first call to "el.hasCls(...)" is calling the hasCls method on the component future, which returns the future itself.

    This explains why the expect() is failing, as ST.future.Component.hasCls() doesn't return a boolean, but a future instance instead:

    http://docs.sencha.com/sencha_test/2.1.0/api/ST.future.Element.html#method-hasCls

    In this particular use case, you don't actually need the expect(), as the future's hasCls() method acts as a tacit assertion of the existence of the class on the future's component.