Commit 96c7bd03 authored by Mike Greiling's avatar Mike Greiling

fix wait_for_vue_resource to not rely on global Vue object

parent 632497bd
/* eslint-disable no-param-reassign, no-plusplus */
import Vue from 'vue';
import VueResource from 'vue-resource';
Vue.use(VueResource);
// Maintain a global counter for active requests
// see: spec/support/wait_for_vue_resource.rb
Vue.http.interceptors.push((request, next) => {
Vue.activeResources = Vue.activeResources ? Vue.activeResources + 1 : 1;
window.activeVueResources = window.activeVueResources || 0;
window.activeVueResources += 1;
next(() => {
Vue.activeResources--;
window.activeVueResources -= 1;
});
});
// Inject CSRF token so we don't break any tests.
Vue.http.interceptors.push((request, next) => {
// needed in order to not break the tests.
if ($.rails) {
// eslint-disable-next-line no-param-reassign
request.headers['X-CSRF-Token'] = $.rails.csrfToken();
}
next();
......
module WaitForVueResource
def wait_for_vue_resource(spinner: true)
Timeout.timeout(Capybara.default_max_wait_time) do
loop until page.evaluate_script('Vue.activeResources').zero?
loop until page.evaluate_script('window.activeVueResources').zero?
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment