Skip to content

Instantly share code, notes, and snippets.

@abreckner
Created May 9, 2014 01:56
Show Gist options
  • Save abreckner/110e28897d42126a3bb9 to your computer and use it in GitHub Desktop.
Save abreckner/110e28897d42126a3bb9 to your computer and use it in GitHub Desktop.
Jasmine 2 plug in to re-enable waitsFor and runs functionality
// This is the equivalent of the old waitsFor/runs syntax
// which was removed from Jasmine 2
waitsForAndRuns = function(escapeFunction, runFunction, escapeTime) {
// check the escapeFunction every millisecond so as soon as it is met we can escape the function
var interval = setInterval(function() {
if (escapeFunction()) {
clearMe();
runFunction();
}
}, 1);
// in case we never reach the escapeFunction, we will time out
// at the escapeTime
var timeOut = setTimeout(function() {
clearMe();
runFunction();
}, escapeTime);
// clear the interval and the timeout
function clearMe(){
clearInterval(interval);
clearTimeout(timeOut);
}
};
@RoyTinker
Copy link

This is really useful for testing a Promise library.

@kumar155
Copy link

kumar155 commented Dec 20, 2017

@SimenB, @RoyTinker
i'm getting this error 'expect' was used when there was no current spec, this could be because an asynchronous test timed out

it('validate target view data for application option auto gaps', () => {
	// component mount
        const Component = mount(
            h(Provider, { store }, [
                h(IntlProvider, { locale: 'en' },
                    h(RDSMContainer),
                )],
           ));
     Component.find('.dropdown-choice').first().simulate('click');
     waitUntil(function () {
            // update the component
            Component.update();
            return Component.find('.targetView').length > 0
        }).then((result) => {
            const TargetComponent = RDSMComponent.find(TargetView);
            expect(TargetComponent.instance().state.applications.length > 0).toBe(true);
      },3000);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment