Simulate the passage of time in protractor?

后端 未结 2 1440
独厮守ぢ
独厮守ぢ 2021-01-06 09:33

I have a few spots where things happen in the UI on a delay using $timeout or $interval. Here\'s a simplified example:

Controller code:



        
2条回答
  •  独厮守ぢ
    2021-01-06 09:45

    You can decorate $timeout and $interval to override the delay supplied to them:

    lower-wait-time.js

    exports.module = function() {
        angular.module('lowerWaitTimeDecorator', [])
        .config(function($provide) {
            $provide.decorator('$timeout', function($delegate) {
                return function() {
                    // The second argument is the delay in ms
                    arguments[1] = arguments[1] / 10;
                    return $delegate.apply(this, arguments);
                };
            });
        })
    };
    

    Usage

    beforeAll(function() {
        var lowerWaitTime = require('lower-wait-time');
        browser.addMockModule('lowerWaitTimeDecorator', lowerWaitTime.module);
    });
    
    afterAll(function() {
        browser.removeMockModule('lowerWaitTimeDecorator');
    });
    
    it('My-sped-up-test', function() {
    
    });
    

提交回复
热议问题