mdasberg / ng-apimock

Node plugin that provides the ability to use scenario based api mocking: for local development for protractor testing
MIT License
99 stars 26 forks source link

ng-Apimock fails when disabling the Control Flow #28

Closed wswebcreation closed 6 years ago

wswebcreation commented 6 years ago

In the future the Control Flow will be disabled. With protractor you can now already disable it by adding this flag in your config SELENIUM_PROMISE_MANAGER = false, see also here.

When you now disable it you will get this error:

     TypeError: deferred.fulfill is not a function
          at /Users/wswebcreation/example/dist/ng-apimock/protractor.mock.js:166:26

This can easily be fixed with this in the protractor.mock.js-file.

    /**
     * Executes the api call with the provided information.
     * @param httpMethod The http method.
     * @param urlSuffix The url suffix.
     * @param options The options object.
     * @param errorMessage The error message.
     * @return {Promise} The promise.
     * @private
     */
    function _execute(httpMethod, urlSuffix, options, errorMessage) {
        const opts = {
            headers: {
                'Content-Type': 'application/json',
                'ngapimockid': ngapimockid
            }
        };

        if (options !== undefined) {
            opts.json = options;
        }

        return new Promise((resolve, reject) => {
            request(httpMethod, baseUrl + urlSuffix, opts).done((res) => res.statusCode === 200 ? resolve() : reject(errorMessage));
        });
    }

We need to create a PR and check alle the usages of protractor.promise.defer and replace it with native promises.

mdasberg commented 6 years ago

thanks I will pick it up

mdasberg commented 6 years ago

fixed in release 1.4.2

wswebcreation commented 6 years ago

Tnx!!