Search code examples
javascriptinternleadfoot

Multiple THEN statements in intern functional test


I have a test that will do something and test that x is visible -

'WHEN something THEN x is visible': function () {
        var myClass= new MyClass(this.remote);
        return myClass
            doSomething()
            .findById('x')
            .isDisplayed()
            .then(function (isDisplayed) {
                assert.isTrue(isDisplayed, 'X should be visible')
            });
    }

I now want to assert that y is hidden, i.e. WHEN something THEN x is visible AND y is hidden

How would I write this in Intern? I could write a separate test for this, but loading the app is quite expensive and I would like to combine as many assertions into one test as possible whilst trying to keep tests as atomic as possible.


Solution

  • If you return another promise from your .then() handler, the resolution of the promises will be chained, and your async test should wait for the entire chain to be resolved (making the code below up, just to give an idea):

    .then(function (isDisplayed) {
        assert.isTrue(isDisplayed, 'X should be visible');
    
        return myClass
            .doSomeOtherThing()
            .findById('y')
            .isHidden()
            .then(function (isHidden) {
                assert.isTrue(isHiddem, 'Y should be hidden');
            });
    });